File gets saved twice on local harddrive

Joe Green 141 Reputation points

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);  
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
{count} votes