Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
After deploying my website on IIS. the Excel is not opening. but its working fine with localhost.

C#
protected void LinkButton1_Click(object sender, EventArgs e)
    {
        string s = "~//Template/Aug.xlsx";
        
        string directoryPath = Path.Combine(Server.MapPath(s));

        System.Diagnostics.Process.Start(directoryPath);
    }


How then can i open the excel which i uploaded in WebFolder in client PC.
Posted
Updated 27-Dec-15 20:24pm
v2

Path name is wrong and cannot even compile. Use verbatim string literal format @"..\..", or escape each \ with \\. Use relative or absolute path, "~\.." won't work. Read about valid path names in any manual for the OS users.

Anyway, there are no situations where hard-coded path name can be used in production-grade software.

—SA
 
Share this answer
 
In addition to Solution 1 -

You also need to consider what you are attempting to do. I hope that you do know that you are attempting to open Excel on the server? Think about it for just one second, since your code runs on the server then it will attempt to open Excel on the server.

And before you ask why it works on the localhost, the reason is that you development machine is both the client and the server.
 
Share this answer
 
Comments
shaprpuff 28-Dec-15 2:25am    
Thanks for the help but then how can i open the excel which i uploaded in WebFolder in client PC.
phil.o 28-Dec-15 2:42am    
Have the client download the Excel file and handle it locally.
AnvilRanger 28-Dec-15 9:48am    
If you describe what you are attempting to do we would be in a better position to help you.

Why would you want to open Excel on the server to start with?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900