
【场景】预览自定义文件
【案例】预览在服务器自定义目录的文件
(1)数据准备,服务器临时目录下的文件

(2)插件案例

```csharp
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.JSON;
using Kingdee.BOS.ServiceHelper.FileServer;
using Kingdee.BOS.Util;
using System;
using System.Web;
namespace DynamicFormPlugIn.Attachment
{
[Kingdee.BOS.Util.HotUpdate]
public class CustomPdfPreviewPlugIn : AbstractBillPlugIn
{
public override void ButtonClick(ButtonClickEventArgs e)
{
if (string.Equals(e.Key, "F_BHR_CustomPdfPreview", StringComparison.OrdinalIgnoreCase))
{
PreviewPdf();
}
}
/// <summary>
/// 本地服务预览 pdf文件
/// </summary>
private void PreviewPdf()
{
string fileName = "2.pdf";
string serverPath = string.Format("TempfilePath/{0}", fileName);
string physicalPath = System.IO.Path.Combine(PathUtils.GetPhysicalPath("TempfilePath"), fileName);
JSONObject webobj = new JSONObject();
webobj["action"] = "OpenRes";//使用客户端本地程序直接打开文件资源,如pdf默认谷歌浏览器打开,word默认使用office打开
string url = FileServerHelper.GetAppSiteOuterNetUrl(this.Context, HttpContext.Current.Request);
string filepath = string.Format("{0}{1}", url, serverPath);
//var logInfo = GetLogInfo(dyn