こんにちは、私が選んだ名前で保存するファイル名があります。フォームで保存をクリックすると、保存ダイアログオプションが表示され、そのウィンドウのファイル名に、何らかの名前のような自分のファイル名を付けたいと思います。彼が保存をクリックすると、保存したいと思いますそのファイル...
何か案が..
実際、次のようにファイルを保存するコードを作成しました
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;
}
しかし、このポントで私は問題を抱えています
strFilePath = Directory.GetCurrentDirectory();
strFilePath = Directory.GetParent(strFilePath).ToString();
strFilePath = Directory.GetParent(strFilePath).ToString();
strFilePath = strFilePath + "\\ACH\\";
私の要件に従って、その特定のパスに保存しています。しかし、私がこれのexeファイルを作成し、Cに直接インストールできるものをいくつか与えると、その問題を克服するために、ユーザーがファイルを保存できるように、ファイルの保存ダイアログを選択したいと思います。必要..