Hi,
I am writting a textfile to c:\ Temp folder. I want to check whether there is Temp folder available in c: , before i save the files in c:/Temp.If there is no folder called Temp in c:,then i want to create a new folder[Temp] dynamically. Can somebody give me an suggetion to do it
My existing code is:
public void TextWrite() { string logPath = (string) (new System.Configuration.AppSettingsReader()).GetValue( "DataAccessLogPath", typeof(string));
////////////////////"DataAccessLogPath" is <add key="DataAccessLogPath" value="c:\Temp\"></add> given in App.Config file.
DataTable dt= Context.QueryDataTable(Sql.Select( RootSystem.Bills.WOWJ_NO, RootSystem.Bills.AssetID,RootSystem.Bills.SuiteID,RootSystem.Bills.LeaseID, RootSystem.Bills.OrganizationID,RootSystem.Bills.OrganizationName,RootSystem.Bills.ContactID, RootSystem.Bills.Address,RootSystem.Bills.BatchID,RootSystem.Bills.ChargedDate ) .Where(RootSystem.Bills.IsBilled==0)); string BatchID="Bill"+DateTime.Now.Day.ToString()+DateTime.Now.Month.ToString ()+DateTime.Now.Year.ToString () ; StringBuilder str = new StringBuilder(); for(int i=0;i<=dt.Rows.Count - 1; i++) { for(int j=0;j<=dt.Columns.Count - 1; j++) { if(dt.Columns[j].ColumnName.ToString ()=="BatchID") str.Append(BatchID.ToString() + "\t"); else str.Append(dt.Rows [j].ToString() + "\t"); } str.Append("\r\n"); } string filename=logPath+BatchID+".txt"; StreamWriter writer = new StreamWriter(filename); writer.WriteLine(str.ToString()); writer.Close();
.NET Development9
|