How to create a new text filename if it exists in window forms using C#net
-
Hi all, pls help me in my application using C#.net (window form) i need to save a .txt file. but if the same filename exist i need to save it as a new filename. i have searched in net but could only find deleting existing or overwritting on the file. pls help to get some solution
-
Hi all, pls help me in my application using C#.net (window form) i need to save a .txt file. but if the same filename exist i need to save it as a new filename. i have searched in net but could only find deleting existing or overwritting on the file. pls help to get some solution
u can use GUID(Global Unique Identifier) for saving the text file with unique name
-
Hi all, pls help me in my application using C#.net (window form) i need to save a .txt file. but if the same filename exist i need to save it as a new filename. i have searched in net but could only find deleting existing or overwritting on the file. pls help to get some solution
One very simple approach I take is simply create a while-loop that increments an integer, appends it to the filename (without the extension, of course), and checks for existence (after re-appending the extension). So long as that filename exists, I increment the variable again and try the next number. Remember to include a failsafe in case the loop accidentally runs forever. Limit it to 10 or 100 iterations for example. I suppose a for-loop would be more convenient in this case then, but a while loop is more syntactically meaningful.
It has become appallingly obvious that our technology has exceeded our humanity. - Albert Einstein
-
Hi all, pls help me in my application using C#.net (window form) i need to save a .txt file. but if the same filename exist i need to save it as a new filename. i have searched in net but could only find deleting existing or overwritting on the file. pls help to get some solution
One of the System.IO classes, I think it is Path, has a method that returns a unique file name.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )