How can i save the file on the same existing file to add to it if existed ?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<pre class="prettyprint" style=" public void Save(string path , bool Locked , PictureBox pb)
{
if (File.Exists(path + "\" + "DATABASE" + "\" + wo_name))
{
string fnexist = path + "\" + "DATABASE" + "\" + wo_name;
}
string fn = path + "\" +"DATABASE" +"\" + wo_name + "\" + wo_name + ".txt";
OptionsFile setting_file = new OptionsFile(fn);[/code]
First time if its a new file the the variable wo_name is only a name without the .txt in the end for example: test
So i build the variable fn all paths including a sub path with the file name and then add txt in the end to create the file.
In the second time i check above if the File.Exists then wo_name is allready text.txt so when im doing

<pre class="prettyprint" style=" path + "\" + "DATABASE" + "\" + wo_name[/code]
In the second time it will be for example: c:DATABASEtest.txt but i need to check if the file exist so it should be like: c:DATABASEtesttest.txt
So how can i make the File.Exists to check for the file ? In the beginning i used the regular fn variable to check if the file exists but then it was :

c:DATABASEtest.txttest.txt.test.txt somethingl ike that. And it should be c:DATABASEtesttest.txt

*** When im saving to the same file second time i want to overwrite all over the file. Not adding from last point or something but overwrite if the file exist.


<
danieli
<br/>

View the full article
 
Back
Top