Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2005

Tip: Looking for answers? Try searching our database.

save file with different name !

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jameel - 20 Oct 2005 09:40 GMT
Hello,

uptill now i able to save the files to the server with thier original names, but i want to save the files with different names to avoid duplication of file names. see the following for what i have acheived uptill now :
strFileName = txtFileName.PostedFile.FileName
strFileName = System.IO.Path.GetFileName(strFileName)
'Save Uploaded file to server
strFileNamePath = strFileFolder & strFileName

If Not (txtFileName.PostedFile Is Nothing) Then
Try
 txtFileName.PostedFile.SaveAs(strFileNamePath)
Catch ex As Exception
 Response.Write("Error Saving File <Br> " & ex.Message.ToString)
 Return False
End Try

Please help me ! I would really appreciate if you would write me some code, not only explain me !
Peter Rilling - 20 Oct 2005 10:19 GMT
You can do two things.

1)  You could use something like File.Exists to see if the file already exists, if it does then append a number on the filename, for instance MyFile.txt (1), MyFile.txt (2), etc.
2)  You could generate a unique name regardless of what it was originally named using the Guid class.  You won't be able to tell what each file is, but you won't have conflicts.

 Hello,

 uptill now i able to save the files to the server with thier original names, but i want to save the files with different names to avoid duplication of file names. see the following for what i have acheived uptill now :
 strFileName = txtFileName.PostedFile.FileName
 strFileName = System.IO.Path.GetFileName(strFileName)
  'Save Uploaded file to server
  strFileNamePath = strFileFolder & strFileName

  If Not (txtFileName.PostedFile Is Nothing) Then
  Try
   txtFileName.PostedFile.SaveAs(strFileNamePath)
  Catch ex As Exception
   Response.Write("Error Saving File <Br> " & ex.Message.ToString)
   Return False
  End Try

 Please help me ! I would really appreciate if you would write me some code, not only explain me !

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.