gpt4 book ai didi

c# - 在执行时创建目录 MVC 6

转载 作者:太空宇宙 更新时间:2023-11-03 15:27:22 26 4
gpt4 key购买 nike

我正在使用它的 byte[] 在数据库中上传文件。要将文件保存在可执行位置的字典中,我使用以下代码。但它在 MVC 6 中工作

protected string CreateDirectory()
{
try
{
string strDirPath = string.Empty;
#region Create directory at executable location
string path = Assembly.GetExecutingAssembly().Location;
FileInfo fileInfo = new FileInfo(path);
string dir = fileInfo.DirectoryName;
string dirFolderName = "\\Uploads";
#endregion
//Create Directory at executable path
if (!Directory.Exists(dir + dirFolderName))
{
Directory.CreateDirectory(dir + dirFolderName);
}
strDirPath = dir + dirFolderName;
return strDirPath;
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}

}

此代码给出如下错误:

CS0117  'Assembly' does not contain a definition for 'GetExecutingAssembly' ProjectName.DNX Core 5.0    

请帮助我如何在 MVC 6 中创建字典

最佳答案

代替

Assembly.GetExecutingAssembly().Location;

使用

typeof(SomeClassInTheCurrentlyExecutingAssembly).GetTypeInfo().Assembly.Location

由于您使用的是 DNX 5.0,因此 GetExecutingAssembly() 不存在。

关于c# - 在执行时创建目录 MVC 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34761145/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com