C# 询问位置以保存使用c创建的文本文件#
我正在将datagridview数据导出为文本文件格式, 我尝试了下面的代码C# 询问位置以保存使用c创建的文本文件#,c#,winforms,datagridview,savefiledialog,C#,Winforms,Datagridview,Savefiledialog,我正在将datagridview数据导出为文本文件格式, 我尝试了下面的代码 string dirLocationString = @"C:\Users\palanar\Desktop\result.txt"; StreamWriter sW = new StreamWriter(dirLocationString); string lines = ""; lines = "DateTime" + "\t" + "TestStatu
string dirLocationString = @"C:\Users\palanar\Desktop\result.txt";
StreamWriter sW = new StreamWriter(dirLocationString);
string lines = "";
lines = "DateTime" + "\t" + "TestStatus" + "\t" + "BatPackSN" + "\t" + "CellSN"
+ "\t" + "BlockSN" + "\t" + "UI_ID" + "\t" + "UI_ParentID" + "\t" + "OperationNumber"
+ "\t" + "OperationName" + "\t" + "EquipmentNumber" + "\t" + "EquipmentName" + "\t" + "WorkOrder"
+ "\t" + "Assembly" + "\t" + "ProductName" + "\t" + "HandlingDuration" + "\t" + "OperationDuration"
+ "\t" + "RepairID" + "\t" + "DefectID" + "\t" + "UitemLevelCode" + "\t" + "UIEventLevelCode";
sW.WriteLine(lines);
for (int row = 0; row < dataGridView2.Rows.Count - 1; row++)
{
string lines1 = "";
for (int col = 0; col <= 19; col++)
{
lines1 += (string.IsNullOrEmpty(lines1) ? " " : "\t") + dataGridView2.Rows[row].Cells[col].Value.ToString();
}
sW.WriteLine(lines1);
}
string dirLocationString=@“C:\Users\palanar\Desktop\result.txt”;
StreamWriter sW=新的StreamWriter(dirLocationString);
字符串行=”;
lines=“DateTime”+“\t”+“TestStatus”+“\t”+“BatPackSN”+“\t”+“CellSN”
+“\t”+“BlockSN”+“\t”+“UI\u ID”+“\t”+“UI\u ParentID”+“\t”+“OperationNumber”
+“\t”+“操作名称”+“\t”+“设备编号”+“\t”+“设备名称”+“\t”+“工作顺序”
+“\t”+“程序集”+“\t”+“产品名”+“\t”+“处理持续时间”+“\t”+“操作持续时间”
+“\t”+“修复ID”+“\t”+“缺陷ID”+“\t”+“UitemLevelCode”+“\t”+“UIEventLevelCode”;
sW.WriteLine(行);
for(int row=0;row 对于(int col=0;col您正在查找的saveFileDialog
例如:
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Text file(*.txt)|*.txt";
sfd.FilterIndex = 1;
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) { return; }
string dirLocationString = sfd.FileName;
你应该使用
@Ganesh_Devlekar,windows桌面应用程序。旁注:在使用IDisposable
时,使用将其包装成,在您的情况下,使用(StreamWriter sW=new StreamWriter…{…}
另外,vb.net
标记在这里是无用的,它是c
only@ArchanaPalani-问题中的代码完全不必要,因为它与您的问题完全无关。只发布所需的代码。
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
//your selected file location
string dirLocationString = sfd.FileName;
}