没有应用程序与此操作指定的文件相关联 [英] No application is associated with the specified file for this operation

查看:1827
本文介绍了没有应用程序与此操作指定的文件相关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我已经编写了一个用于打印.pdf文件的代码,但未在Windows窗体应用程序中显示PrintDialog,但是在启动过程时,如 p.Start()显示错误(没有应用程序与指定的文件关联此操作).

这是我的代码:
1.我已经从一个网址下载了.pdf文件
2.然后打印该.Pdf文件

Hi to All,
I have wrote a code for print a .pdf file without showing PrintDialog in windows form application but when the process is start like p.Start() is showing error (No application is associated with the specified file for this operation).

Here is my code :
1.I have download the .pdf file from an Url
2.Then Print that .Pdf file

string UrlName = Url.ToString();
            string DownloadFilePath = @filePath+"\\"+FileName;
            if (File.Exists(DownloadFilePath))
            {
                File.Delete(DownloadFilePath);
            }
            //Downloading file from Http Url
            WebClient myWebClient = new WebClient();
            myWebClient.DownloadFile(UrlName, DownloadFilePath);            
            System.Threading.Thread.Sleep(1000);
            //Code for Print the PDF file
            Process P = new Process();           
            P.StartInfo.FileName = DownloadFilePath; // FileName(.pdf) to print.
            P.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //Hide the window.                        
            P.StartInfo.Verb = "Print";
            PrintDialog pd = new PrintDialog();
            //PrinterSettings setting = new PrinterSettings();           
           
            P.StartInfo.Arguments = pd.PrinterSettings.PrinterName.ToString();
            pd.PrinterSettings.MaximumPage = 1;
            P.StartInfo.CreateNoWindow = true; //!! Don't create a Window.    
            P.Start();
            P.WaitForExit(4000);
            P.CloseMainWindow();

推荐答案

该代码不一定会打印PDF-它会尝试使用默认的应用程序打开PDF扩展名(PDF).

该错误消息表示您的系统中未注册任何此类应用程序,因此请检查:
1)您正在输出带有文件名的PDF扩展名.
2)您的打印应用程序已注册为PDF文件的默认处理程序.
That code won''t necessarily print a PDF - it tries to open a PDF using the default application for the extension (PDF).

The error message implies that no such application is registered in your system, so check:
1) That you are outputting the PDF extension with the file name.
2) That your print app is registered as the default handler for PDF files.


这篇关于没有应用程序与此操作指定的文件相关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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