如何将文件保存在桌面的文件夹没有什么路径是什么? [英] how to Save a file at folder at the desktop no mater what the path is?

查看:121
本文介绍了如何将文件保存在桌面的文件夹没有什么路径是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

,你可以看到我正在导出水晶报告到一个PDF文件
,但我的问题是,水晶报告RPT文件的路径和保存oupt文件的路径(PDF文件)自文件夹的路径桌面会在PC之间更改,例如

as you can see I am exporting crystal report to a PDF file but my problem is that the path of the crystal report RPT file and path of saving the oupt file (PDF File) since the path to folder at desktop is will be changed between PCs like

PC1路径代码

C:\Users\Xuser\Desktop

并且在def default pc是

and on def rent pc is

C:\Users\XYPC\Desktop

所以路径不是一个静态路径..反正出路?

so the path is not a static path .. anyway way out ?

更新:

现在下面的代码获取桌面路径,访问路径被拒绝的访问权限的异常

now below code get the path to desktop but i am getting exception about access permissions which is access to path is denied

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


推荐答案

Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)以获取桌面的路径。

David Fulop建议使用 Environment.GetFolderPath(Environment.SpecialFolder.Desktop) DesktopDirectory 桌面之间有什么区别?

David Fulop suggested using Environment.GetFolderPath(Environment.SpecialFolder.Desktop). What's the difference between DesktopDirectory and Desktop?

到MSDN:


  • 桌面是逻辑桌面而不是物理文件系统位置。

  • DesktopDirectory 是用于在桌面上物理存储文件对象的目录。

  • Desktop is "the logical Desktop rather than the physical file system location."
  • DesktopDirectory is "the directory used to physically store file objects on the desktop."

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

Source for all of the above: https://msdn.microsoft.com/en-us/library/system.environment.specialfolder%28v=vs.110%29.aspx

这篇关于如何将文件保存在桌面的文件夹没有什么路径是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆