question

LouYovin-6751 avatar image
0 Votes"
LouYovin-6751 asked XingyuZhao-MSFT commented

Wrong data in file downloaded via webclient.DownloadFile

Console program written in C# has been running for several years as a cron job. I down load documents from a sharepoint site containing document libraries for several (~20) users. Users sync to their library on their PC's. Each library contains documents (excel and pdf) in the root as well as in sub-folders. The program connects to the site, using sharepoint credentials and then downloads all new/changed documents to our on-site server using the webclient.download method. This worked well until a couple of months ago. Now, documents in the root contain incorrect data. Documents in the sub folders have correct data. Downloading via the GUI and via sync is correct. Example document named test.txt, containing "this is text", contains this (much truncated to be able to post):



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"



Downloading via REST API resolves the problem for the root, I am still using the downloadfile method for sub folders

dotnet-csharpdotnet-standard
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.

LouYovin-6751 avatar image
0 Votes"
LouYovin-6751 answered XingyuZhao-MSFT commented

The method return is void. It just downloads the file into the target folder.
I think we are on different pages here. Anyway, thank you very much for the help. Since I have a work around, I am OK. Mostly posted in case someone else has the same problem.

Lou

· 1
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.

Hi @LouYovin-6751 ,
It seems that your problem has been solved, then please click '"Accept Answer" on your reply.
Thank you for your cooperation.

0 Votes 0 ·
cooldadtx avatar image
0 Votes"
cooldadtx answered

Just a rough guess at this point since you didn't post any code but I'm assuming there is an error in that HTML. Can you post the request and response code you're using, the HTTP status code and the contents of the HTML?

DownloadFile doesn't do anything special. It literally just sends a GET request to the given URL and anything that is returned back is dumped to a file. Whether the content was a file to begin with or not isn't relevant to this method.

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.

LouYovin-6751 avatar image
0 Votes"
LouYovin-6751 answered cooldadtx commented

Program is a Console program written in C#
much code to get the list of users from SP and then get file last modified dates, etc.
Down load Code goes something like this, simplified:
get sharepoint credentials
var client = new WebClient();
client.getCredentials (a method written to get credentials)
client.DownloadFile(webUrl (to doc library containing file), Targetfolder+@"\"+filename);

As I said, program has worked OK for several years.

· 1
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.

We need to see the results of the call. Can you post the HTTP status code and the HTML contents that were returned? It could be that your credentials are failing now, there is a redirect that is happening or something so that information would be useful. If necessary turn on network tracing so you can see the request/response information. You can also look at the ResponseHeaders to see if there is any new headers such as a redirect URL.

0 Votes 0 ·