2011-06-21 126 views
0

我想要写入和读取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()); 
     } 

    } 
+0

您正在使用哪个版本的Windows? –

+2

好吗?你检查了权限吗?该文件是否在另一个进程中打开?该文件是否是只读的?到目前为止你检查了什么? – Cameron

+2

另外,与你的问题完全无关,你可能想看看美妙的'System.Path'类(特别是['Combine()'](http://msdn.microsoft.com/en-us/library/ fyy7a5kt.aspx)方法)。 – Cameron

回答

0

我觉得你在Windows Vista上运行的程序/ 7 尝试使用应用程序清单文件

<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> 
<security> 
    <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> 
    <!-- UAC Manifest Options 
     If you want to change the Windows User Account Control level replace the 
     requestedExecutionLevel node with one of the following. 

    <requestedExecutionLevel level="asInvoker" uiAccess="false" /> 
    <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> 
    <requestedExecutionLevel level="highestAvailable" uiAccess="false" /> 

     Specifying requestedExecutionLevel node will disable file and registry virtualization. 
     If you want to utilize File and Registry Virtualization for backward 
     compatibility then delete the requestedExecutionLevel node. 
    --> 
    <requestedExecutionLevel level="asInvoker" uiAccess="false" /> 
    </requestedPrivileges> 
</security> 

1

“访问被拒绝”的含义正是它所说的。真正的问题是

  • 什么用户是你的代码运行?
  • 哪些资源受到失败操作的影响?
  • 该用户通常对每个资源拥有哪些权限?
  • UAC是否进场?

向世界其他地方询问为什么权限与您的特定系统上的权限是一致的。只有你有能力调查这一点。

这个“问题”给了我一个可怕的冲动,说“plz send me teh configz”。