gpt4 book ai didi

.net - DotNetNuke 文件管理

转载 作者:行者123 更新时间:2023-12-02 04:07:10 26 4
gpt4 key购买 nike

我正在使用 DNN 5.6.2,并且正在尝试构建一个自定义模块,用户可以在其中上传我对其运行验证的文件。如果文件有效,则将其保存。模块创建了一个根级目录“DataValidation”,并且模块的每个实例都创建了一个子目录以保持事物的组织性。

我创建目录没有问题,但是当我上传到它们时,它要么因各种不同的错误而失败,要么奇怪的是文件上传正常,但在 DNN 数据库中它说它位于根级文件夹“DataValidation”中。我的代码或方法有问题吗?

    // Method is called to create the folders before writing to them
public void verifyModuleFolderExists(string subfolderName)
{
bool moduleFolderExists = false;
bool instanceFolderExists = false;

ArrayList folders = FileSystemUtils.GetFolders(PortalId);

foreach (FolderInfo folder in folders)
{
if (folder.FolderPath == "DataValidation/")
{
moduleFolderExists = true;
}

if (folder.FolderPath == subfolderName)
{
instanceFolderExists = true;
}
}

if (!moduleFolderExists)
{
FileSystemUtils.AddFolder(PortalSettings, PortalSettings.HomeDirectoryMapPath, "DataValidation\\");
}

if (!instanceFolderExists)
{
FileSystemUtils.AddFolder(PortalSettings, PortalSettings.HomeDirectoryMapPath + "DataValidation\\", subfolderName);
}
}

// Called on file upload
public void saveUploadedFile(HttpPostedFile uploadedFile, string subFolderName)
{
string path = PortalSettings.HomeDirectoryMapPath + "DataValidation\\" + subfolderName + "/";
string s = FileSystemUtils.UploadFile(path, uploadedFile);
}

最佳答案

我相信问题出在 string path = ...部分,你有“/”,它应该是“\”。这将导致它可能忽略路径的文件夹部分。

所以您的上传代码将更改为

public void saveUploadedFile(HttpPostedFile uploadedFile, string subFolderName)
{
string path = PortalSettings.HomeDirectoryMapPath +
"DataValidation\\" + subfolderName + "\\";
string s = FileSystemUtils.UploadFile(path, uploadedFile);
}

关于.net - DotNetNuke 文件管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7029382/

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