I tried to download the file from the server via the web method but this does not work for me. my code is below
[System.Web.Services.WebMethod()] 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.ClearContent(); Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.WriteFile(file.FullName);
and my ajax call code is below
<script type="text/javascript"> function GetDateTime() { var params = "{'msg':'From Client'}"; $.ajax ({ type: "POST", url: "Default.aspx/GetServerDateTime", data: params, contentType: "application/json;charset=utf-8", dataType: "json", success: function (result) { alert(result.d); }, error: function (err) { } }); } </script>
and I called this function at the click of a button.
I do not know how to upload a file using other methods
Please suggest me any other available methods or give me a fix in the same code.
Thanks to everyone ..
source share