I used the following code to convert a dataset into xls. It works fine but it throws an error. (Some formatting problem)
I want to save an xls file created in a specific location without the user's permission.
conn.Open();
SqlDataAdapter getData = new SqlDataAdapter("SELECT * FROM profile", conn);
data.Clear();
getData.Fill(data);
conn.Close();
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.Charset = "";
response.ContentType = "application/vnd.ms-excel";
response.AddHeader("Content-Disposition", "attachment;filename=\"" +"siv" +"\"");
using (StringWriter sw = new StringWriter())
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
DataGrid dg = new DataGrid();
dg.DataSource = data.Tables[0];
dg.DataBind();
dg.RenderControl(htw);
response.Write(sw.ToString());
response.End();
}
That is obviously not possible because that would pose an enormous security risk . You can't drop files onto the users hard drive.
There is no workaround that doesn't require the users consent. If there was I'd be very nervous to use a web browser...
If you manage to do this you probably are rewarded 50,000$ in cash by Google as part of their security reward program.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.