I am working in a file management system.I have uploaded a document into a directory which is in server and i’ve listed all the uploaded files in a gridview with documentname as linkbutton.
My problem is that i’ve to open that particular file on clicking documentname which is actually a link button. Here’s my code for that.
protected void gdlbtnDocName_Click(object sender, EventArgs e)
{
try
{
LinkButton lkbtn = (LinkButton)sender;
if (File.Exists(lkbtn.CommandArgument))
{
System.Diagnostics.Process.Start(lkbtn.CommandArgument);
}
}
catch (Exception ex)
{
lblMessage.Text = ex.Message.ToString();
}
}
lkbtn.CommandArgument is the filepath say(G:\dms\eg.text).
This code works fine in development centre.But when i published it and run on the localhost, its not working .
Can any one help me please ….
The problem you’re facing is that the Process.Start will run on your server so the document will be opened not on your localhost, but on the server.
If you want to open a document that is stored on the server, you will first have to download it to the local machine.
If that’s not an option, you can create a preview of the document that the user can view in his browser.
How to create the preview depends on the file type you want to display.
For a simple text file, you can just read the file on the server and render the string (make sure to do some Html Encoding!)
In a project I worked on we also had to display PDF and Word files. We ended up using a commercial product from Aspose. When a user uploads a file to the server we immediatelyprocess the file trough Aspose and then cache the result on the file system.