Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hi all,
I would like to save a text file the same name as the original file I open using the open file dialog.
I use open file dialog and have
 
ArrayList fileList = new ArrayList;
 
foreach(string file in fileList)  //where file =C:\Users\Iman\Desktop\Thermo  Data\gygi_vp_0014.mgf
{
    //do stuff
    //and write to text with original filename "gygi_vp0014.mgf" + "modified"
    streamwriter sw = new streamwriter( what do I put here")
}
 
Thanks in advance!
Posted 28-Apr-11 11:05am
Edited 28-Apr-11 11:19am
v2
Comments
PasanRatnayake at 29-Apr-11 0:25am
   
You want to open a file "aaaaaa.mgf", edit it, write the contents to a text file with the name "aaaaaa.mgf modified.txt"? Is it?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

One of the simplest ways to write to a text file is to use File.WriteAllText.
 
See http://msdn.microsoft.com/en-us/library/system.io.file.writealltext.aspx[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

using (StreamWriter writer= new StreamWriter(“test.txt”))
{
     while(true); // note, it fills the disk up very quickly.
     {
         writer.WriteLine(“test StreamWriter”);
         writer.Flush();
     }
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 28 Apr 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100