//DECLARE A LIST OF FILE NAMES: List<string> ListOfFilesToMove = spExecuter.ExecuteDataRow<List<string>>("dbo.Archivos_MOV_LIST", ParameterArtId);
try
{
string TempPath = new ConfigModel().GetByKey("PATH_ARCHIVOS_TEMPORALES").Value; //TEMP FILES WHERE THEY ARE NOW
string FinalPath = new ConfigModel().GetByKey("PATH_ARCHIVOS").Value; //DESTINATION FILE TO MOVE
using (WebClient client = new WebClient()) //JUST CONNECT
{
foreach(var arch in ListOfFilesToMove) //FOR EVERY RECORD IN MY LIST
{
var TempFile = Path.Combine(TempPath, arch); //COMBINE PATH + FILE NAME
File.Move(TempFile, FinalPath); //MOVE THE FILE
}
}
}
I was wondering if i can rename the files when they are moved because i have a table on my Database like this:
TempFileName / FinalName
ABC1.pdf / ABC1_1234.pdf
So i could call another list of Final Names and match them to rename the files but i think this is a bad idea. SHould i Create some of those special lists with two attribs like TempFileName and FinalName and just make one StoreProcedure to get both at same
time?
I was wondering if i can rename the files when they are moved because i have a table on my Database like this:
TempFileName / FinalName
ABC1.pdf / ABC1_1234.pdf
Do you mean that you already have this two colums in your database table and you want to rename the TempFileName with the FinalName when you move the File?
MVC_user
So i could call another list of Final Names and match them to rename the files but i think this is a bad idea. SHould i Create some of those special lists with two attribs like TempFileName and FinalName and just make one StoreProcedure to get both at same
time?
If I didn't misunderstand above, I think both two method is ok, you can get the TempFileName and FinalName from the database and then change the filename and move, or you can first move then change the name.
Best Regards,
Jiadong Meng
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
36 Points
132 Posts
Move files with new name?
Mar 16, 2020 03:33 PM|MVC_user|LINK
This is my code:
I was wondering if i can rename the files when they are moved because i have a table on my Database like this:
TempFileName / FinalName
ABC1.pdf / ABC1_1234.pdf
So i could call another list of Final Names and match them to rename the files but i think this is a bad idea. SHould i Create some of those special lists with two attribs like TempFileName and FinalName and just make one StoreProcedure to get both at same time?
Somebody have some rename examples?
All-Star
53021 Points
23601 Posts
Re: Move files with new name?
Mar 16, 2020 03:54 PM|mgebhard|LINK
You can rename a file to whatever you like. Are you asking if it is possible to rename the file using the File.Move() method?
Parameters
<div class="propertyInfo">
The name of the file to move. Can include a relative or absolute path.
</div> <div class="propertyInfo stack">
The new path and name for the file.
</div>
Is your code not working as expected or throwing an exception?
Member
36 Points
132 Posts
Re: Move files with new name?
Mar 16, 2020 07:16 PM|MVC_user|LINK
is not what i was having on mind but thanks.
I just did a SP evaluating two parameters, when you pass the second it receives the other list matching the new name.
Participant
1320 Points
491 Posts
Re: Move files with new name?
Mar 17, 2020 08:08 AM|jiadongm|LINK
Hi MVC_user,
Do you mean that you already have this two colums in your database table and you want to rename the TempFileName with the FinalName when you move the File?
If I didn't misunderstand above, I think both two method is ok, you can get the TempFileName and FinalName from the database and then change the filename and move, or you can first move then change the name.
Best Regards,
Jiadong Meng