Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good evening all

I am having a issue with downloading a file in the correct format, so after downloading the file it comes out has 0000-00000-000000-000000. so i'm force renaming the file which shows correctly in my folder how ever when im trying to send the file else where it send has 0000-00000-000000-000000 instead of the format I saved it has. Any advice would be great thanks.

What I have tried:

C#
string FileName= Application.StartupPath + @"\FileName.ff";

                   string Location = Program.Settings.FileLocation.Location + @"\";
                   Location += new Guid().ToString();
                       wc.DownloadFile("download link", FileName);
                      SendFile(FileName, @Location)

                     // if (File.Exists(FileName))
                           //File.Delete(FileName);

                   }


The location is stored in Json file



UPDATE:

So I figured out wrong it's the
new Guid().ToString();
is renaming the file, how ever without it it don't want to send, is it any better alteratives I could use other that GUID or a way to convert it ?
Posted
Updated 23-Mar-23 15:22pm
v5
Comments
PIEBALDconsult 23-Mar-23 19:30pm    
(gibbering)
Ummm... maybe it's the @ in @Location ? What is it doing there? Otherwise, I have no clue.
DafyddB 23-Mar-23 20:44pm    
It just calling a saved directory in the Json File, I sort of figured out what wrong it the += new Guid().ToString();, but without it it won't work, im not sure what else I could use or how I could convert it to the original file name.
PIEBALDconsult 23-Mar-23 21:08pm    
Well, other than the odd formatting of the Guid, I expect it's doing exactly what you told it to do.
The Guid ought to be formatted as 00000000-0000-0000-0000-000000000000.
Graeme_Grant 23-Mar-23 21:20pm    
Literal string ... rather than
string Location = Program.Settings.FileLocation.Location + "\\";

1 solution

You need to use the factory method of the Guid class:
C#
Location += Guid.NewGuid();

ref: Guid.NewGuid Method (System) | Microsoft Learn[^]

You can also simplify it to:
C#
string Location
  = @$"{Program.Settings.FileLocation.Location}\{Guid.NewGuid()}";


Another option is to use: Path.GetTempFileName Method (System.IO) | Microsoft Learn[^]
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900