Bonjour à tous, je vais avoir un nom de fichier à enregistrer avec le nom que je choisis. Comme quand je clique sur enregistrer sur mon formulaire je vais montrer une option de dialogue de sauvegarde et sur le nom de fichier de cette fenêtre je voudrais avoir le nom de mon propre nom comme un nom quelconque et quand il clique sur enregistrer je voudrais enregistrer ce fichier ...Est-il possible de sauvegarder le fichier avec le nom que je désire?
une idée ..
en fait, je l'ai écrit un code pour enregistrer mon fichier comme suit
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;
}
Mais à ce pont que j'ai un problème
strFilePath = Directory.GetCurrentDirectory();
strFilePath = Directory.GetParent(strFilePath).ToString();
strFilePath = Directory.GetParent(strFilePath).ToString();
strFilePath = strFilePath + "\\ACH\\";
selon mon exigence je sauve dans ce chemin particulier. mais quand je fais un fichier exe de ceci et donne un quelqu'un qu'ils peuvent installer directement dans C: ou un autre répertoire afin de surmonter ce problème, je voudrais opter pour l'utilisateur un dialogue de sauvegarde de fichier afin qu'il puisse enregistrer le fichier où il
Vous pouvez enregistrer avec le nom que vous choisissez s'il n'est pas déjà utilisé (vous avez plusieurs options sur la façon de le gérer, selon le contexte). Je ne comprends pas quelle partie du fichier vous sauvez, vous ne savez pas comment faire. (En outre, en publiant le code que vous avez jusqu'à présent aiderait) – Rox
Rox j'ai ajouté mon exemple de code qui a été fait jusqu'à présent par moi et aussi j'ai dit que mon exigence peut m'aider à obtenir la solution – Dotnet
Voulez-vous offrir de sauver le fichier dans le dossier où l'application est installée? – Rox