我想要寫入和讀取file.rdl在wpf c#中生成報告,但是出現錯誤「Access is denied to the path c:\ Document and Setting \ SipusProv \ 。TEMP \ reportTemp.rdl 這是我的源代碼:訪問被拒絕的路徑C:WPF C#
private void LaporanRdl(string rdl, DataSet data, string judul)
{
DataSet dt = data;
dt.DataSetName= "Data";
Masaddy.Reprot report = new Masaddy.Reprot();
try
{
//System.IO.StreamReader strReader = new System.IO.StreamReader(AppDomain.CurrentDomain.BaseDirectory + @"\rdl\" + rdl + ".rdl");
System.IO.StreamReader strReader = new System.IO.StreamReader(AppDomain.CurrentDomain.BaseDirectory + @"\rdl\" + rdl + ".rdl");
string pathTemp = AppDomain.CurrentDomain.BaseDirectory + @"Temp\reportTemp.rdl";
System.IO.StreamWriter strWriter = new System.IO.StreamWriter(pathTemp);
string strIsi = "";
while (strIsi != "</Report>")
{
strIsi = strReader.ReadLine().Trim();
if (strIsi == "<Value>txtDep</Value>")
{
strIsi = " <Value>" + this.ddDeputi.SelectedItem.ToString() + "</Value>";
}
if (strIsi == "<Value>txtDir</Value>")
{
strIsi = " <Value>" + this.ddDir.SelectedItem.ToString() + "</Value>";
}
if (strIsi == "<Value>txtSubDir</Value>")
{
strIsi = " <Value>" + this.ddSubDir.SelectedItem.ToString() + "</Value>";
}
if (strIsi == "<Value>txtTahun</Value>")
{
strIsi = " <Value>" + this.txtTahun.Text.ToString() + "</Value>";
}
strWriter.WriteLine(strIsi);
}
strWriter.Dispose();
Masaddy.ReportForm r = new Masaddy.ReportForm(AppDomain.CurrentDomain.BaseDirectory + @"\\Temp\\reportTemp.rdl", "Data", dt.Tables[0]);
r.Text = judul;
r.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
您正在使用哪個版本的Windows? –
好嗎?你檢查了權限嗎?該文件是否在另一個進程中打開?該文件是否是隻讀的?到目前爲止你檢查了什麼? – Cameron
另外,與你的問題完全無關,你可能想看看美妙的'System.Path'類(特別是['Combine()'](http://msdn.microsoft.com/en-us/library/ fyy7a5kt.aspx)方法)。 – Cameron