Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
dt = (DataTable)ViewState["Data"];
           if (dt.Rows.Count != 0)
           {
               string file = new ExcelHelper().ExportToExcel(dt);
               string rootPath = HttpContext.Current.Server.MapPath("~\\ExcelFiles\\").ToString();
               string localCopy = Guid.NewGuid().ToString() + ".xlsx";
               File.Copy(file, rootPath + localCopy);
               string str = rootPath + localCopy;
               Response.Write(str);  // not writing anything
               Response.Redirect(str); // not going to path..
           }


file is present , path is also correct..
Posted
Comments
Nathan Minier 21-Oct-14 7:23am    
Have you tried HttpContext.Current.Response ?
Laiju k 21-Oct-14 7:46am    
do you get any error
Madhuri Gamane 21-Oct-14 7:51am    
No..
Check the path while debugging. Also you are redirecting, so how it will write?
Madhuri Gamane 21-Oct-14 7:52am    
path is correct, if i copied same path and paste in another tab it opens....
also in folder's address bar it works..

1 solution

Response.Write(str) will just print the string that is in str at the top of the page which I doubt is what you really want.

However, you then call Response.Redirect(str) which, if str were correct, would go to a new page and so your previous Response.Write would be lost anyway.

Also, you can't redirect to str because you have it set to a local file path. str looks something like c:\inetpub\wwwroot\MyApp\ExcelFiles.

If you are trying to download the Excel file to the client you can do Response.Redirect("~/ExcelFiles/" + fileName);
 
Share this answer
 
Comments
Madhuri Gamane 21-Oct-14 8:37am    
Thank you..
path must be Response.Redirect("~/ExcelFiles/" + fileName);
ZurdoDev 21-Oct-14 8:55am    
You're welcome.

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