I have created excel file from asp.net table and am now able to download it.
Now I want to save this excel file on the server to be able to use it. I have tried to use string-writer to save the file folder, without succeeding. Here is my code which I have have written to generate file from asp.net.
tbl_loctbl.Controls.Clear();
LoadDetails();
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=ProfessorWise.xls");
Response.ContentType = "application/ms-excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(sw);
tbl_loctbl.RenderControl(hw);
Response.Write(sw.ToString());
Response.End();
From this code, file is generated and downloaded to user pc.Loaddetails()
is function where I load data to asp.net table and then excel file generated.
How can I save it to server?
If i understood your questing correctly, you want to save files on your webserver with your webapplication.
If you are using IIS on your webserver to run your c# application, then you need to give your folder applicationpool permission where you want to write the excel file/folder to.
the applicationpool must be the same as the webapplication is using.
First you need to give permission to your folder where you are saving the files/folders. The permission you need to give is the applicationpool your webapplication is using.
After that in IIS you right-click on your site and add a virtual directory. Here you can define the Alias of the folder. Your code will recognize this as an actual folder in project. And you need to chooses the actuall phisical path here.