Not able to save/download file on local pc. File is available insde code in byte[].

Ritesh Kavankar 1 Reputation point
2022-09-17T12:35:30.657+00:00

Hello Team,

I am working on sharepoint web aplication backend c# and hosted on azure.
Basically I working on virtual machine. Using citrix to access pc.

I have file data in format of byte[] array in side code and want to save/download it on local, but i am not able to do that.

For download I used response streams
Example :- Response.output (data) / Response.Binarywrite(data).

This Didn't work

Or

To save on local I used desktop path

string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)

Above code return some different location wich is not accessible for me.
Error : D:/Windows/System32 not accessible.

Previously I used above code to access desktop it always work without any error.
But looks like as I am working on virtual machine and aplication is also hosted on azure that's why it's returning some different path.

Please help me how I can save/download file on my local.

Thanks in advance.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,252 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,665 questions
Windows Server Storage
Windows Server Storage
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Storage: The hardware and software system used to retain data for subsequent retrieval.
631 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 31,571 Reputation points
    2022-09-17T15:51:40.913+00:00

    This Didn't work

    What error did you get? Did you set the content headers to indicate a file download?

    https://stackoverflow.com/questions/10008628/force-file-download-header

    It is not clear to me where exactly your code is running. Since you commented "backend", then I would think that your code is executing on the web server and doesn't have direct access to the file system of the client. Your "user" from an environment point of view is the IIS worker process identity.

    If your code sees D:/Windows/System32 then that sounds more like the Citrix server. In Citrix, are you publishing a full desktop or just some executable? It may not be considered an interactive logon.

    https://stackoverflow.com/questions/13850839/why-environment-specialfolder-desktop-is-empty

    Is your code able to access C:\Users? What subfolders do you see? Is there a folder that matches your client user's ID?


  2. MotoX80 31,571 Reputation points
    2022-09-19T17:11:52.543+00:00

    But unfortunately i don't have access of my file system.
    (C:\ inetpub\wwwroot\ste.exe)

    That's just a test file that I have on my pc that I tried to download. You should test with any file that your site has access to. Use a simple test.txt file to test with.

    and for the hosted application it was not working.

    I'm sorry, but a description of "it was not working" really doesn't help. For all I know, your web site hosting provider could be blocking file downloads. Or your pc/browser is doing something that is blocking the download.

    When I observe response data in network tab i found something which may blocking our cookies.

    For a file download, I wouldn't think that cookies would play a role in that. But I could be wrong. Are different sites involved in the request? Ie; the user browses https://somesite.com/page.aspx, but when they click on the link/button it gets sent to https://some-other-site.com/download.aspx

    pls share any links if you have regarding this issue.

    Well the basic "issue" is that I don't know what your "issue" is. If you see an HTTP 200 response in the trace then that means that it should have been successful. I don't know what your browser did with the data.

    What kind of file are you trying to download. Try downloading a simple text file.

    What are the response headers that you get? (Right click the request, select copy, then "copy response headers".

    HTTP/1.1 200 OK  
    Cache-Control: no-cache, no-store  
    Pragma: no-cache  
    Content-Type: application/octet-stream; charset=utf-8  
    Expires: -1  
    Server: Microsoft-IIS/10.0  
    Content-Disposition: attachment; filename="test.txt"  
    Content-Description: File Transfer  
    Content-Transfer-Encoding: binary  
    X-AspNet-Version: 4.0.30319  
    X-Powered-By: ASP.NET  
    Date: Mon, 19 Sep 2022 16:49:17 GMT  
    Content-Length: 872  
    

    In the developer tools, also check the console and security tabs. Anything there?