hi I don't know Russian thats why I'll use translate for convert my text to Russian so I'm if anything wrong
// English Version //
I want to export the data's in datagridview to csv file I created a class for export option then call class from the button but I'm getting the error
the code I attached to button from form
the errror message : System.UnauthorizedAccessException: ''C:\Users\Danthe\Desktop\VisualStudio\excel2\bin\Debug\Excel' Access denied to path.'
// Russian Version //
Я хочу экспортировать данные из datagridview в csv-файл, я создал класс для опции экспорта, затем вызываю класс с помощью кнопки, но я получаю сообщение об ошибке
код, который я прикрепил к кнопке из формы
сообщение об ошибке : System.UnauthorizedAccessException: ''C:\Users\Danthe\Desktop\VisualStudio\excel2\bin\Debug\Excel' Access denied to path.'
------------------------------------
Я не знаю русского языка, поэтому я использовал перевод, чтобы перевести его на русский. Мне жаль, если я был неправ
// English Version //
I want to export the data's in datagridview to csv file I created a class for export option then call class from the button but I'm getting the error
C#:
using System.Windows.Forms;
namespace excel2
internal class ExportHelper
{
public bool Export(DataGridView dgv)
{
bool exported = false;
List<string> lines = new List<string>();
DataGridViewColumnCollection column = dgv.Columns;
bool firstDone = false;
StringBuilder columnLine = new StringBuilder();
foreach(DataGridViewColumn col in column)
{
if(!firstDone)
{
columnLine.Append(col.DataPropertyName);
firstDone = true;
}
else
{
columnLine.Append("," + col.DataPropertyName);
}
}
lines.Add(columnLine.ToString());
//data lines
foreach(DataGridViewRow row in dgv.Rows)
{
StringBuilder dataLine = new StringBuilder();
firstDone = false;
foreach(DataGridViewCell cell in row.Cells)
{
if (firstDone)
{
dataLine.Append(cell.Value);
firstDone= true;
}
else
{
dataLine.Append(","+cell.Value);
}
lines.Add(dataLine.ToString());
}
}
string file = Path.Combine(Application.StartupPath, "Excel");
File.WriteAllLines(file,lines); //this line giving error
System.Diagnostics.Process.Start(file);
return exported;
}
}
the code I attached to button from form
C#:
private void button8_Click(object sender, EventArgs e)
{
new ExportHelper().Export(dataGridView1);
}
the errror message : System.UnauthorizedAccessException: ''C:\Users\Danthe\Desktop\VisualStudio\excel2\bin\Debug\Excel' Access denied to path.'
// Russian Version //
Я хочу экспортировать данные из datagridview в csv-файл, я создал класс для опции экспорта, затем вызываю класс с помощью кнопки, но я получаю сообщение об ошибке
Код:
using System.Windows.Forms;
namespace excel2
internal class ExportHelper
{
public bool Export(DataGridView dgv)
{
bool exported = false;
List<string> lines = new List<string>();
DataGridViewColumnCollection column = dgv.Columns;
bool firstDone = false;
StringBuilder columnLine = new StringBuilder();
foreach(DataGridViewColumn col in column)
{
if(!firstDone)
{
columnLine.Append(col.DataPropertyName);
firstDone = true;
}
else
{
columnLine.Append("," + col.DataPropertyName);
}
}
lines.Add(columnLine.ToString());
//data lines
foreach(DataGridViewRow row in dgv.Rows)
{
StringBuilder dataLine = new StringBuilder();
firstDone = false;
foreach(DataGridViewCell cell in row.Cells)
{
if (firstDone)
{
dataLine.Append(cell.Value);
firstDone= true;
}
else
{
dataLine.Append(","+cell.Value);
}
lines.Add(dataLine.ToString());
}
}
string file = Path.Combine(Application.StartupPath, "Excel");
File.WriteAllLines(file,lines); //this line giving error
System.Diagnostics.Process.Start(file);
return exported;
}
}
код, который я прикрепил к кнопке из формы
C#:
private void button8_Click(object sender, EventArgs e)
{
new ExportHelper().Export(dataGridView1);
}
сообщение об ошибке : System.UnauthorizedAccessException: ''C:\Users\Danthe\Desktop\VisualStudio\excel2\bin\Debug\Excel' Access denied to path.'
------------------------------------
Я не знаю русского языка, поэтому я использовал перевод, чтобы перевести его на русский. Мне жаль, если я был неправ