Hi, I have a webservice method which is going to download a file (pop up window with Open or Save the file). I notice webservice might not accept HttpContext.Current.Response?? I have below method which doesn't work for me and prompt error "System.Xml.XmlException: Data at the root level is invalid" .. .but if i created another method just return a test string value, pass to my ASPX page and print it out, it works ... :( It just doesn't print the line from the webmethod. Any idea or workaround this?
[WebMethod]
public void DownloadFile(string fileName)
{
string filepath = fileName;
FileInfo file = new FileInfo(filepath);
if (file.Exists)
{
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
HttpContext.Current.Response.ContentType = ReturnExtension(file.Extension.ToLower());
HttpContext.Current.Response.TransmitFile(file.FullName);
HttpContext.Current.Response.End();
}
}