Hi all i will have some file name to be saved with the name i choose . Like when i click on save on my form i will show a save dialog option and on the file name of that window i would like to have the filename of my own like some or other name and when he clicks on save i would like to save that file...
ANy idea..
Actually i have written a code to save my file as follows
public bool savePPD(string strPath)
{
m_flag = true;
string FileName = strPath;
string m_strDate = DateTime.Now.ToString("MM/dd/yyyy");
m_strDate = m_strDate.Replace("/", "");
strPath += "/PPD_EntryDetailRecord_" + m_strDate + ".txt";
if (File.Exists(strPath))
{
int index = 1;
FileName += "/PPD_EntryDetailRecord_" + index + "_" + m_strDate + ".txt";
while (File.Exists(FileName))
{
string strFilePath;
strFilePath = Directory.GetCurrentDirectory();
strFilePath = Directory.GetParent(strFilePath).ToString();
strFilePath = Directory.GetParent(strFilePath).ToString();
strFilePath = strFilePath + "\\ACH\\";
FileName = strFilePath + "/PPD_EntryDetailRecord_" + ++index + "_" + m_strDate + ".txt";
}
using (TextWriter tw = new StreamWriter(FileName))
{
tw.Write(m_strRecordTypeCode.PadLeft(1, '0'));
tw.Write(m_strTransactionCode.PadLeft(2, '0'));
tw.Write(m_strRecievingDFIIdentification.PadLeft(9, '0'));
//tw.Write(m_strCheckDigit.PadLeft(1, '0'));
tw.Write(m_strDFIAccountNumber.PadRight(17, ' '));
tw.Write(m_strAmount.PadLeft(10, '0'));
tw.Write(m_strIndividualIdentificationNumber.PadRight(15, ' '));
tw.Write(m_strIndividualName.PadRight(22, ' '));
tw.Write(m_strDiscretionaryData.PadRight(2, ' '));
tw.Write(m_strAddendaRecordIndicator.PadLeft(1, '0'));
tw.Write("TTTTBBBBZZZZZZZ");
tw.WriteLine();
//tw.Flush();
tw.Close();
StreamWriter sw = File.AppendText(FileName);
string file1 = Directory.GetCurrentDirectory();
file1 = Directory.GetParent(file1).ToString();
file1 = Directory.GetParent(file1).ToString();
file1 = file1 + "\\ACH";
string[] fileEntries = Directory.GetFiles(file1, "TempPPDAddenda.txt");
StreamReader sr = new StreamReader(fileEntries[0]);
string s;
s = sr.ReadToEnd();
sr.Close();
sw.Write(s);
sw.Close();
}
}
if (!(File.Exists(strPath)))
{
using (TextWriter tw = new StreamWriter(strPath))
{
tw.Write(m_strRecordTypeCode.PadLeft(1, '0'));
tw.Write(m_strTransactionCode.PadLeft(2, '0'));
tw.Write(m_strRecievingDFIIdentification.PadLeft(9, '0'));
tw.Write(m_strDFIAccountNumber.PadRight(17, ' '));
tw.Write(m_strAmount.PadLeft(10, '0'));
tw.Write(m_strIndividualIdentificationNumber.PadRight(15, ' '));
tw.Write(m_strIndividualName.PadRight(22, ' '));
tw.Write(m_strDiscretionaryData.PadRight(2, ' '));
tw.Write(m_strAddendaRecordIndicator.PadLeft(1, '0'));
tw.Write("TTTTBBBBZZZZZZZ");
tw.WriteLine();
tw.Close();
StreamWriter sw = File.AppendText(strPath);
string file1 = Directory.GetCurrentDirectory();
file1 = Directory.GetParent(file1).ToString();
file1 = Directory.GetParent(file1).ToString();
file1 = file1 + "\\ACH";
string[] fileEntries = Directory.GetFiles(file1, "TempPPDAddenda.txt");
StreamReader sr = new StreamReader(fileEntries[0]);
string s;
s = sr.ReadToEnd();
sr.Close();
sw.Write(s);
sw.Close();
}
}
return m_flag;
}
But at this pont i am having an issue
strFilePath = Directory.GetCurrentDirectory();
strFilePath = Directory.GetParent(strFilePath).ToString();
strFilePath = Directory.GetParent(strFilePath).ToString();
strFilePath = strFilePath + "\\ACH\\";
as per my requirement i am saving in that particular path. but when i make an exe file of this and give some one they can install directly in C: or some othe directory so inorder to overcome that problem i would like to opt the user a save file dialog so that he can save the file where he required..