Click here to Skip to main content
12,816,490 members (31,399 online)
Rate this:
Please Sign up or sign in to vote.
See more: WebService
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..
Posted 22-Aug-12 22:53pm
ryanb31 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)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170308.1 | Last Updated 23 Aug 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100