C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
7,547 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
In .Net 6 using c#, I'm saving a test.pdf file to users temp folder (C:\Users\username\AppData\Local\Temp) but when I inspect the temp folder, I see file is saved twice one with a name upload_8d6371d032cfee57008b853cd3c87ae9.pdf and another copy with name test.pdf. I'm not sure why the file is being written twice and if I can get rid of this file upload_8d6371d032cfee57008b853cd3c87ae9.pdf or avoid file being written twice.
Here is my code
// Full path to users local temp file folder, file.Name is test.pdf
string myTempFile = Path.Combine(Path.GetTempPath(), file.Name);
var httpClient = new HttpClient();
using (Stream stream = await httpClient.GetStreamAsync(remoteFileUrl).ConfigureAwait(false))
{
using FileStream fileStream = new(myTempFile, FileMode.Create);
stream.CopyTo(fileStream);
}
No, only 185 KB in size. It doesn’t matter if it’s pdf, jpeg, etc. it creates file twice.
Are you using an external URL?
It looks strange that a downloaded file is called "upload...".
Yes not sure why it is called upload_
The url is not external. I’m running application on local machine, uploading/selecting a file from local drive and saving it in local temp folder.
@Joe Green , Welcome to Microsoft Q&A, based on my test, I could your code to download a file one time without the problem in .net 6.0 console app. I guess that there are two reasons to cause the problem.
First, Please check if there is some other code to affect the result. Such as other code also download or copy the file. I recommend that you could create a new project to test the code to check if you still have the problem.
Second, Maybe your url is a specific url. You could try the url
https://i.stack.imgur.com/y7Alc.png
, which I tested it without the problem.@Joe Green , is any update?
Sign in to comment