访问被拒绝到路径C:WPF C#

时间:2011-06-21 01:25:04

标签: c# wpf

我想写和读取file.rdl以在wpf c#中生成报告,但是有一个错误“路径c:\ Document和设置\ SipusProv \ Temp \ reportTemp.rdl拒绝访问。 这是我的源代码:

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());
        }

    }

2 个答案:

答案 0 :(得分:1)

“拒绝访问”意味着它所说的内容。真正的问题是

  • 您的代码运行的用户是什么?
  • 失败的操作会影响哪些资源?
  • 该用户通常对这些资源拥有哪些权限?
  • UAC是否会发挥作用?

向世界其他地方询问为什么权限与您的特定系统相同并不是一件好事。只有你能够对此进行调查。

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

答案 1 :(得分:0)

我想你在Windows Vista / 7下运行程序 尝试使用Application Manifest文件

  <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>