-1

I am working on a ticketing system for my company using Asp.net and c#. User can create a ticket and attach a few documents to it (mostly word and excel documents). I upload and save the documents in the web server in a dedicated location (i.e. C:\Attachments).

Now, when user opens a previously created ticket, I show the list of the attachments as link buttons in a Gridview. I want user to be able to open the attachment by clicking on the link button. I have achieved this in my local machine in development, but when I publish the web app into IIS Server, I don't know how to open the files saved inside the web server. How do I provide the path for the file? Should I first download the file in the client machine and then open it? Any help is much appreciated.

This is how I open the attachment in development (which is the OnClick event of the link button):

protected void OpenAttachment(object sender, EventArgs e)
{
   string FileName;
   FileName = @"C:\Attachments\Test.docx";
   Process.Start(FileName);          
}
Ralf Bönning
  • 14,515
  • 5
  • 49
  • 67
A.G.
  • 1
  • 1
  • 1
    `Process.Start` is going to open the file on the machine the website is running on -- namely the webserver. http://stackoverflow.com/questions/37650/how-to-implement-a-file-download-in-asp-net – Paul Abbott Oct 28 '16 at 20:02
  • 1
    You don't generally "open" the files for the user. Some formats you may be able to display in the browser (such as text files or PDF's) but all files you can provide to the user for downloading, by setting the appropriate content type and writing the bytes of the file to an HTTP response. The user can then open the file with whatever compatible program they have. – mason Oct 28 '16 at 20:06
  • Thank you for your answers. You led me to the right direction. – A.G. Oct 28 '16 at 21:36

1 Answers1

1

You have to change your approach in order to get the desired result.

Currently you create a new process on the web server by Process.Start. So you will see this process on your development environment because client and server are on the same computer.

In order to open a file by the browser, it has to be downloaded first. By adding the right content type, the browser can decide how to proceed with the downloaded file.

There are plenty of tutorials available. A starting point is this related StackOverflow question: How to implement a file download in asp.net

Community
  • 1
  • 1
Ralf Bönning
  • 14,515
  • 5
  • 49
  • 67