DotNetNuke 文件管理
我正在使用 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);
}
I'm working with DNN 5.6.2 and i'm trying to build a custom module where users can upload a file that I run validation against. If the file is valid then it is saved. There is one root level directory "DataValidation" that the module creates and each instance of the module creates a subdirectory to keep things organized.
I have no problems creating the directories but when I upload to them it either fails with various different errors or strangely the file uploads fine but in the DNN database it says that it is in the root level folder, "DataValidation". Is there something wrong with my code or approach?
// 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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信问题出在
string path = ...
部分,你有“/”,实际上应该是“\”。这可能会导致它忽略路径的文件夹部分。所以你的上传代码将更改为
I believe the issue is with the
string path = ...
part, you have "/" which should really be "\". That would cause it to ignore the folder part of the path potentially.So your upload code would change to