大家好,我将使用我选择的名称保存一些文件名。就像当我在我的表单上单击保存时,我将显示一个保存对话框选项,并且在该窗口的文件名上,我希望拥有自己的文件名,例如某个或其他名称,当他单击保存时,我想保存那个文件...
任何的想法..
实际上我已经编写了一个代码来保存我的文件,如下所示
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: 或其他目录中,所以为了克服这个问题,我想为用户选择一个保存文件对话框,以便他可以将文件保存在他的位置必需的..