Click here to Skip to main content
14,691,000 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have tried to download the file from the server through the webmethod but it has not work for me. my code as below
public static string GetServerDateTime(string msg)
    String result = "Result : " + DateTime.Now.ToString() + " - From Server";
    System.IO.FileInfo file = new System.IO.FileInfo(System.Web.HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["FolderPath"].ToString()) + "\\" + "Default.aspx");
    System.Web.HttpResponse Response = System.Web.HttpContext.Current.Response;
    Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
    Response.AddHeader("Content-Length", file.Length.ToString());
    Response.ContentType = "application/octet-stream";
    return result;        

and my ajax call code is as below
 <script type="text/javascript">
    function GetDateTime() {
                    var params = "{'msg':'From Client'}";
                          type: "POST",
                          url: "Default.aspx/GetServerDateTime",
                          data: params,
                          contentType: "application/json;charset=utf-8",
                          dataType: "json",
                          success: function (result) {
                          error: function (err) {


and i have called this function in button click..

i don't know how to download the file with other methods

Please suggest me if any other methods available or give the correction in the same code.

Thanks to all..
ZurdoDev 23-Aug-12 8:25am
Have you tried just doing a Response.Redirect() to the file instead?
Này Thì Xoắn 8-Jan-15 4:19am
It doesn't work

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