Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi Friends,

I am facing an issue when I run my code in Production Env.
Same code I am running into my machine with IIS and its working fine here.

This code generates the excel with exported data. Which works fine locally, but in production it says the highlighted error.


404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.


Help will be appretiated enough.
C#
protected void linkExportExcel_Click(object sender, EventArgs e)
        {
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("Cache-Control", "max-age=3");
            Response.AddHeader("Pragma", "public");
            Response.AddHeader("content-disposition", "attachment;filename=LeaveBalanceAsOn(" + DateTime.Now.ToString("MM-dd-yyyy") + ").xls");

            Response.Charset = "";
            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            Response.ContentType = "application/vnd.xls";
            Response.Write(hidHtml.Value);
            //Response.Write(hidHtml.Value);
            Response.Flush();
            Response.End();
        }
Posted
Updated 8-Aug-14 8:07am
v2
Comments
Sergey Alexandrovich Kryukov 8-Aug-14 14:11pm    
What file? what directory? You don't show any file system operation, so how to you expect someone to find your bug? See if you use some hard-coded paths in your entire code...
—SA
myself.panku 8-Aug-14 20:23pm    
Hi Mika,

Thanks for your instant revert on the question.

But as you have asked i haven't mentioned any file operation in the the above peice of code, so that's all what I have written, i am not using the Introp for creating Excel object and adding 1 by 1 row into the Excel.Application object, this is what I avoid to do.
I have used the conent-disposition which will generate the .xls file irrespective of if there is excel installed in the server or not , bcoz the file needs to be opened at client.

The same piece of code runs in my office site which is deployed in production, I know this could be resolved by some web.config resolution but what are these required changes that I am missing here.

I hope this will make it clear to all, what I am expecting.

Few things to check:
- Excel properly installed
- the file actually exists
- correct working path is used

In your method, you can use File.Exists[^] method to check if the file actually exists and if not use a proper method to communicate the error.
 
Share this answer
 
Hi Mika,

Thanks for your instant revert on the question.

But as you have asked i haven't mentioned any file operation in the the above peice of code, so that's all what I have written, i am not using the Introp for creating Excel object and adding 1 by 1 row into the Excel.Application object, this is what I avoid to do.
I have used the conent-disposition which will generate the .xls file irrespective of if there is excel installed in the server or not , bcoz the file needs to be opened at client.

The same piece of code runs in my office site which is deployed in production, I know this could be resolved by some web.config resolution but what are these required changes that I am missing here.

I hope this will make it clear to all, what I am expecting.
 
Share this answer
 

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