不会将文件下载到“我的文档”文件夹

本文关键字:文档 我的文档 文件夹 我的 文件下载 | 更新日期: 2023-09-27 18:37:09

我的一位客户对我的 ActiveX 控件有问题。ActiveX 应该下载一个 Excel 文件,将其保存在"我的文档"中的文件夹中,然后运行 Excel 并打开该文件。

以下是下载和打开文件的代码片段:

    private string Checkout(string strFileUrl, string strPhysicalDir, string strPhysicalName)
    {            
        string strMyDocumentFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        string strCiroDocFolder = String.Format(@"{0}'CiroDoc", strMyDocumentFolder);
        string strCheckoutFolder = String.Format(@"{0}'{1}", strCiroDocFolder, strPhysicalDir);
        string strFilePath = String.Format(@"{0}'{1}", strCheckoutFolder, strPhysicalName);
        try
        {
            if (!Directory.Exists(strCiroDocFolder))
                Directory.CreateDirectory(strCiroDocFolder);
            if (!Directory.Exists(strCheckoutFolder))
                Directory.CreateDirectory(strCheckoutFolder);
            if (File.Exists(strFilePath))
                File.Delete(strFilePath);
            WebClient myWebClient = new WebClient();
            myWebClient.DownloadFile(strFileUrl, strFilePath);               
        }
        catch (Exception e)
        {
            return e.Message;
        }
        return Run(strFilePath);
    }
    private string Run(string strFilePath)
    {
        if (!File.Exists(strFilePath))
            return "filenotfound";
        if (IsExecutable(strFilePath))
            return "isexecutable";
        try
        {
            System.Diagnostics.Process.Start(strFilePath);
        }
        catch (Exception e)
        {
            //This get returned
            return String.Format("{0} ({1})", e.Message, strFilePath);
        }
        return "success";     
    }

Run 方法返回异常"将命令发送到程序时出错"。

当我检查"我的文档"文件夹时,该文件不存在。由于它不存在,我希望 Run 方法停止并返回"filenotfound"。

这让我感到困惑。为什么File.Exists会返回true?是Windows文件虚拟化启动并且文件保存在VirtualStore文件夹中吗?如果是这样,如何阻止这种行为?或者可能是客户机器中的其他原因导致了这种行为?

我还没有能够在我自己的机器上重现这个问题。如果你知道我会如何感激。

我的客户的计算机设置

  • 操作系统: 视窗 7
  • 浏览器: IE 10
  • 防病毒软件:迈克菲

如果我缺少一些相关信息,我会尝试获取它。

不会将文件下载到“我的文档”文件夹

如果 Internet Explorer 处于保护模式并启用了 UAC,System.Diagnostics.Process.Start(strFilePath);则无法按预期运行。

改用此代码将打开 Excel 文件,即使在保护模式下也是如此。

Process myProcess = new Process();
myProcess.EnableRaisingEvents = false;
myProcess.StartInfo.FileName = "excel";
myProcess.StartInfo.Arguments = String.Format(@"""{0}""", strFilePath);
myProcess.Start();