473,386 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

save file with different name !

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 !
Nov 19 '05 #1
1 1974
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.

"Jameel" <sk*******@hotmail.com> wrote in message news:ew**************@TK2MSFTNGP10.phx.gbl...
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 !
Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: GJP | last post by:
Hello. Ive been asked to make my own notepade for college assignment. All ig going well, but i cant get the save to work. I can get Save a (shows dialog box), i can get it to just save too,...
0
by: Bala | last post by:
Hi In my vb program, I'll store xml element tag name into vb control tag property and I'll save the data to xml file using tag value(name of the xml tag) and control value (value of that control)....
8
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box...
5
by: peter | last post by:
Hello all, I'm looking for an advice. Example (one block in ascii file): $------------------------ NAME='ALFA' CODE='x' $------------------------
1
by: David Lozzi | last post by:
Howdy, I've decided to try and use the gridview and a sqldatasource. When I add the sqldatasource connection (to MSDE 2000) and press save, I get "Visual Studio has encountered an unexpected...
8
by: why? | last post by:
Im working with Python 2.2 on my red hat linux system. Is there any way to write python codes in separate files and save them so that i can view/edit them in the future? Actually I've just started...
9
by: nik | last post by:
Hi, I would like to create a class and then save it for re-use later. I have tried to use pickle, but am not sure if that is right. I am sorry, but I am new to python. Basically, I have a...
0
Boxcar74
by: Boxcar74 | last post by:
Hi Everybody!!! I have an Issue. I have an Excel file that queries an Access db. I’m trying to have it so I don’t have to keep updating it manually everyday and save it to a network drive...
3
by: evenlater | last post by:
I have an Access application on a terminal server. Sometimes my users need to export reports to pdf, rtf or xls files and save them to their own client device hard drives. They can do that right...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.