How to link files from a website

Our application server has a folder used to store attachments downloaded by the client. This folder is called the attachments that are located outside the website, not the virtual directory for this folder. I wonder how to link the files of this folder. My code is:

string vetting = "c:\\Attachments";
if (Directory.Exists(vetting +"\\"+ "UserName"))
        {

            DirectoryInfo di = new DirectoryInfo(vetting+"\\" + "UserName");
            FileInfo[] rgFiles = di.GetFiles("*.*");
            if (rgFiles.Length > 0)//thumb.db will be a file
            {//list is a div on front end.
                list.InnerHtml += <span class='SubTitle'>Your attachments list:</span>";
                foreach (FileInfo fi in rgFiles)
                {
                    list.InnerHtml += "<br><a href='c:/Attachments/UserName/"+fi.Name+"'>"+fi.Name+"</a>" ;
                }
            }
            else
            {
                list.InnerHtml += "You don't have any attachment yet.";
            }
        }

But this will not work, you always need to find the client side c: / Attachments. How can I refer to the server c: / Attachments? Thank you in advance.

+3
source share
3 answers

You cannot link to these files if they are not displayed in IIS (your web server).

Suggest 2 options:

  • .ashx(- ASP.NET) . ( , cookie, ). .InnerHtml <a href='mysite.com/bar.ashx?file=foo'>foo.xlsx</a>. , . .

  • / IIS. vdir. . // . . , IIS NTFS . , /. .InnerHtml <a href='mysite.com/attachments/foo.xlsx'>foo.xlsx</a>

+1

C Drive , -. , , C Drive. -, .

0

Naturally, it goes into the directory structure on the client side, where the browser works. He does not know how the server is configured.

You need to expose these links via HTTP and, therefore, they need an address that resolves an address that knows how to resolve these files on the server to available resources via HTTP.

0
source

All Articles