question

RiteshKavankar-5258 avatar image
0 Votes"
RiteshKavankar-5258 asked TongZhangMSFT-7548 commented

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

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.

sharepoint-devwindows-server-storagedotnet-aspnet-webpages
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MotoX80 avatar image
0 Votes"
MotoX80 answered RiteshKavankar-5258 commented

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?


· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hey

Thanks for replay.

You have almost understood the exact problem.
Let clear some confusion.

On my laptop I have installed Citrix and I am working on virtual pc there.

My Aplication is basic SharePoint provider hosted app. Front-end SharePoint UI+ backend c#

1) When I say this is not working that means I am not getting any kind of exceptions when I use response to download. I have tried multiple code like below link you have provided.

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

Btw all this response code are working on another application which running on local, without publishing.

2) In Citrix I publish complete site there.

3) I am not able access c://users through code and yes there is subfolder that matches with my client I'd.

The link that you shared interactive logon it looks more familiar with our problem.

Do we have solution so I can save/download that file on Citrix pc. File is available inside code in byte[] format.
If backend code don't have access then can we use Java script to download that []byte data.


Please help.

0 Votes 0 ·
MotoX80 avatar image MotoX80 RiteshKavankar-5258 ·

Press F12 in your browser to open up the developer tools. Click on the network tab and recreate the download. Examine the headers and the response data and see if you can find some error status.


242231-image.png


0 Votes 0 ·
image.png (142.6 KiB)

Hey sorry for late reply,

I followed the steps that you suggested.
In headers section I found below data.

General


Request url : something
Request method: post
Status code : 200 OK
Remote address : something
Refer policy: strict to origin when cross origin

Response headers:
Content disposition: attachment:filename (Correct)
Content length: (correct)
Date : today's date
Server: Microsoft/ii's10.0

Set cookies: some data + warning symbol (This set- cookies header didn't specify a "same site" attributes and was defaulted to samesite=LAX, and was blocked because it came from a cross site response which was not the response to a top-level navigation. The set cookie had to have been set with "samesite=none" to enable cross site usage )

Set cookies: some data + (extra word in data "samesite:none") + No warning symbol at end

Strict - transport security: max age= no; includes sub domain
X powered by : asp.net

In above code i found setcookie attribute double.
First attribute was with warning.

If you need request data or more specific info about any attribute please let me know.

Thanks,
Ritesh Kavankar

0 Votes 0 ·
Show more comments
MotoX80 avatar image
0 Votes"
MotoX80 answered TongZhangMSFT-7548 commented

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?


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello,

I think we have already discussed concept of interactive logon that there is only c drive in my virtual pc and i don't have access to any folder or file when I try to access it from code wich is hosted on azure.

Regarding download issue, Yes I am using another site to fetch the data (Cross site interaction) and download on current site.

One cookie is bloked in networks response header tab. I have shared screen shot of error.
I am also not sure that this is exact reason for download error but still trying to fix this.

You can search concept of samesite wich has three types :
1) Strict.
2) Lax
3) None.

I will check response headers/security/console tab today as you suggested and let you know if found any suspicious.

Thanks

0 Votes 0 ·

Hi @RiteshKavankar-5258,

I am checking to see if the problem has been resolved. Do you have any further questions about this thread? If you have any questions or progress, you can contact me in time.

Thanks for your understanding.


If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 Votes 0 ·