将文件上传到文件夹

将文件上传到文件夹

本文介绍了将文件上传到文件夹/目录时出现问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的asp .net项目中,我试图查看存储在上载文件夹/目录中的已上传文件,但它显示了它,但是当我尝试查看存储在上载文件夹/子目录中的文件时.

In my asp .net project I am trying to view my uploaded files stored in upload folder/directory it shows it but when I try to view the files stored in folder/sub directory of upload.

protected void Page_Load(object sender, EventArgs e)
    {
        DirectoryInfo di = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath("")+ "\\UserImages\\");
        int i = 0;
        FileInfo[] sortList = di.GetFiles();
        Array.Sort(sortList, new MyDateSorter());
        foreach (FileInfo fi in sortList)
        {
            HyperLink HL = new HyperLink();

            Label lbl = new Label();
            Label lbl1 = new Label();
            HL.ID = "HyperLink" + i++;
            HL.Text ="View";
            lbl1.Text = fi.Name;
            lbl.Text = fi.CreationTime.ToShortDateString();
            //This line is not woking
          HL.NavigateUrl = Server.MapPath("") + "\\UserImages\\" + fi.Name;
            //This line is woking
           //HL.NavigateUrl =fi.Name;
            myPlaceHolder.Controls.Add(lbl1);
            myPlaceHolder.Controls.Add(HL);
            myPlaceHolder.Controls.Add(new LiteralControl("<span style='padding-left:20px'/>"));
            myPlaceHolder.Controls.Add(lbl);
            myPlaceHolder.Controls.Add(new LiteralControl("<br/>"));
        }
    }



主题行减少了[/EDIT}



Subject line decreased[/EDIT}

推荐答案

//This line is not woking
          HL.NavigateUrl = Server.MapPath("") + "\\UserImages\\" + fi.Name;


看起来不正确!

如果UserImages是文件夹,则在部分应用程序中(在根节点内),然后将(〜)用作根节点并映射该文件夹.此外,您可以使用此技巧正确地找到根节点路径并使用它: [ ^ ]

您需要做的就是正确形成网址.在需要时使用VS调试器查看形成的URL,并在需要时进行更正.


Looks incorrect!

If UserImages is a folder, part of your application (inside your root node) then use (~) for root node and map the folder. Further, you can use this tip to correctly find the root node path and use it: Resolving Paths in a Multi-Folder WebSite[^]

All you need is to form the url correctly. Use the VS debugger as and when needed to look the URL formed and rectify it if needed.


这篇关于将文件上传到文件夹/目录时出现问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 09:17