2016-04-26 103 views
0

你可以看到我正在将水晶报告导出到PDF文件 但我的问题是水晶报告RPT文件的路径和保存oupt文件(PDF文件)的路径,因为桌面上文件夹的路径是像如何将文件保存在桌面上的文件夹中,不管路径是什么?

PC1路径代码的PC之间的变化是

C:\Users\Xuser\Desktop 

和DEF租电脑是

C:\Users\XYPC\Desktop 

这样的路径是不是一个静态的路径..反正出路?

更新:

现在下面的代码获取路径到桌面,但我得到有关的访问权限的例外是访问路径被拒绝

private void ExportToPDF() 
    { 

     ReportDocument cryrpt = new ReportDocument(); 

     try 
     { 
      cryrpt.Load("INVOICE_REP.rpt"); 

      ExportOptions CrExportOptions; 
      DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions(); 
      PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions(); 
      CrDiskFileDestinationOptions.DiskFileName = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); 
      MessageBox.Show(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)); 
      CrExportOptions = cryrpt.ExportOptions; 
      { 
       CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; 
       CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat; 
       CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions; 
       CrExportOptions.FormatOptions = CrFormatTypeOptions; 
      } 
      cryrpt.Export(); 

      MessageBox.Show("Export Done"); 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.ToString()); 
     } 
    } 
+0

System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) – LaneL

回答

1

您可以使用环境类。

Environment.GetFolderPath(Environment.SpecialFolder.Desktop); 
1

使用Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)获取桌面路径。

David Fulop建议使用Environment.GetFolderPath(Environment.SpecialFolder.Desktop)DesktopDirectoryDesktop有什么区别?

根据MSDN:

  • Desktop是 “逻辑桌面,而不是物理文件系统位置。”
  • DesktopDirectory是“用于在桌面上物理存储文件对象的目录”。

来源为上述所有:https://msdn.microsoft.com/en-us/library/system.environment.specialfolder%28v=vs.110%29.aspx

+0

这是伟大的,但现在我得到了访问权限的错误消息是访问路径被拒绝 – samer

+0

你能编辑你的问题来包含产生错误的代码吗? –

+0

我已更新我的代码 – samer

相关问题