0

I created an asp.net site for downloading documents. I handle this with Page.Response.

try {
...
    EndpointAddress endPoint = new EndpointAddress("xxxxx.svc");
    FileServiceClient fileServiceProxy = new FileServiceClient(binding, endPoint);
    // WCF WebService call
    Stream stream = fileServiceProxy.GetFileStream(filePath);

    Page.Response.ContentType = "application/pdf";
    Page.Response.AddHeader("Content-Disposition",string.Format   ("attachment; fileName=\"{0}\"", Path.GetFileName(filePath)));
    Page.Response.AddHeader("Accept-Ranges", "bytes");
    if (buffer != null){
        Page.Response.BinaryWrite(buffer);
    }
    Page.Response.Flush();
}
catch (Exception e)
{
    Page.Response.Clear();
    Page.Response.ClearContent();
    Page.Response.ClearHeaders();
}
finally
{
    Page.Response.End();
}

And while the file is loading from a webservice I want to display a hourglass cursor. Showing loading cursor is working.

protected void Page_Load(object sender, EventArgs e)
{
    btnDownload.Attributes.Add("onclick", "document.body.style.cursor = 'wait';");
}

But I can't change it back to normal cursor. I think because I don't fire a post back or don't reload the site. What can I do to set default cursor if buttonClick event is over without site reload!?

Update: Updated the code with the wcf webservice call. I call the webservice with file path and get a stream back which I write to Page.Response.BinaryWriter

GermanSniper
  • 249
  • 1
  • 5
  • 19
  • 1
    This is far more complicated than it looks. See [Can you use Javascript to detect a file download window created server side?](http://stackoverflow.com/q/3055138/464709) for the gory details. – Frédéric Hamidi Jan 29 '15 at 14:41
  • What do you mean with `the file is loading from a webservice`? How do you make the call? With jQuery's ajax? Or is it a script service? Either way you should have an `oncomplete` event... – SmartDev Jan 29 '15 at 14:42

1 Answers1

0

@ Frédéric Hamidi THX for the link. I change my approach and display a jquery waiting dialog until file transfer is finished.

File download dialog

GermanSniper
  • 249
  • 1
  • 5
  • 19