Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to everybody.,

I have a problem with renaming a file in asp .net. The problem is that

=> I am uploading .pdf format file through a page and assigning the file name through some fields text. And i am storing that file in folder of the project and file name in database.

But while updating the file i will not select the new file, but i want to change the name of that old file in database as well as file which is in the particular folder.

so how i can change the name of the file in folder? I'm getting to change the name in database but not in folder file name.

Thanks.
Posted
Updated 13-Jun-11 1:33am
v2

Use the File.Move[^] method.
 
Share this answer
 
Comments
#realJSOP 13-Jun-11 7:35am    
5 - proposed as answer
Sergey Alexandrovich Kryukov 13-Jun-11 22:47pm    
Agree, a 5.
--SA
Yes as per the OriginalGriff wrote, if you want to rename the file then, you have to use Move() method which is static method of File class. This class is available in System.IO namespace... <br />
syntax :<br />
<pre>File.Move(oldFileName, newFileName);</pre><br />
or you can use copy and delete command like....<br />
<pre lang="midl">File.Copy(oldFileName, NewFileName);<br />
<br />
File.Delete(oldFileName);</pre><br />
for more details on how to rename file see <a href="http://msdn.microsoft.com/en-us/library/system.io.file(v=vs.71).aspx">this</a>[<a href="http://msdn.microsoft.com/en-us/library/system.io.file(v=vs.71).aspx" target="_blank" title="New Window">^</a>] link...<br />
 
Share this answer
 
Comments
Joemar Valete 14-Jun-11 2:24am    
Agree
I Hope this may Help you...

Link[^]
 
Share this answer
 

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