DotNetNuke 文件管理

发布于 2024-11-29 15:07:58 字数 1519 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

琉璃繁缕 2024-12-06 15:07:58

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

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

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

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

public void saveUploadedFile(HttpPostedFile uploadedFile, string subFolderName)
{
    string path = PortalSettings.HomeDirectoryMapPath + 
                    "DataValidation\\" + subfolderName + "\\";
    string s = FileSystemUtils.UploadFile(path, uploadedFile);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文