Silverlight:业务应用程序需要访问文件才能打印和移动
我对业务应用程序有以下要求: (所有这些都可能在本地或服务器上)Silverlight:业务应用程序需要访问文件才能打印和移动,silverlight,mvvm,printing,Silverlight,Mvvm,Printing,我对业务应用程序有以下要求: (所有这些都可能在本地或服务器上) 允许用户选择文件夹位置 显示文件夹的内容 打印文件夹(*.pdf)中的选定项目 显示已打印的文件 可能将打印文件移动到新位置(打印文件的子文件夹) 如何在Silverlight中实现这一点 亲切问候, 下流的首先,除了最后一项之外,所有的事情都可以完成(按照你期望的方式)。由于安全协议,silverlight无法访问用户的驱动器并对其进行操作。您可以访问silverlight的应用程序存储,这对您没有任何帮助。我将重点介绍如何
- 允许用户选择文件夹位置
- 显示文件夹的内容
- 打印文件夹(*.pdf)中的选定项目
- 显示已打印的文件
- 可能将打印文件移动到新位置(打印文件的子文件夹)
下流的首先,除了最后一项之外,所有的事情都可以完成(按照你期望的方式)。由于安全协议,silverlight无法访问用户的驱动器并对其进行操作。您可以访问silverlight的应用程序存储,这对您没有任何帮助。我将重点介绍如何完成前4项
- 允许用户选择文件夹位置并显示文件夹内容
如果您注意到,在我的示例中,一旦检索到文件,我建议将其上载到Web服务器或具有临时公共访问权限的地方。我建议通过web服务来实现这一点。例如public void OnSelectPDF(object sender) { //create the open file dialog OpenFileDialog ofg = new OpenFileDialog(); //filter to show only pdf files ofg.Filter = "PDF Files|*.pdf"; ofg.ShowDialog(); byte[] _import_file = new byte[0]; //once a file is selected proceed if (!object.ReferenceEquals(ofg.File, null)) { try { fs = ofg.File.OpenRead(); _import_file = new byte[fs.Length]; fs.Read(_import_file, 0, (int)fs.Length); } catch (Exception ex) { } finally { if (!object.ReferenceEquals(fs, null)) fs.Close(); } //do stuff with file - such as upload the file to the server }; }
//configure the system file (customn class) TSystemFile objFile = new TNetworkFile().Initialize(); //get the file description from the Open File Dialog (ofg) objFile.Description = ofg.File.Extension.Contains(".") ? ofg.File.Extension : "." + ofg.File.Extension; objFile.FileData = _import_file; objFile.FileName = ofg.File.Name; //upload the file MasterService.ToolingInterface.UploadTemporaryFileAsync(objFile);
function invokeDownload(_destination) {
//some fancy jquery or just the traditional document.location change here
//open a popup window to http://www.myurl.com/downloads/download.aspx? fileName=_destination
}
下载.aspx的代码超出了我的回答范围,因为它根据需要而变化,只会延长这篇文章(更多)。但从我所给的来看,它会对你所寻找的东西“起作用”,但可能不是你所期望的那样。但是,请记住,这主要是由于silverlight限制。这种方法所做的不是强迫你需要一个插件来查看应用程序中的pdf文件,而是允许用户计算机使用现有的AdobePDF阅读器来扮演它的角色。在silverlight中,至少据我所知,大多数打印都是使用您所称的和“ImageVisual”元素完成的。要直接从silverlight打印pdf,您需要在silverlight控件中查看该pdf,或者要求web服务将pdf呈现为图像,然后将该图像放置在控件中。只有这样你才能直接打印。我将这种方法作为一种更干净、更直接的方法来介绍
需要注意的是,对于temp目录,我建议每次添加文件时,在服务器端清理一段时间。为您节省定期运行某些任务以检查文件夹和删除旧文件的工作。;)
function invokeDownload(_destination) {
//some fancy jquery or just the traditional document.location change here
//open a popup window to http://www.myurl.com/downloads/download.aspx? fileName=_destination
}