コード例 #1
0
        /// <summary>
        /// 获取在线预览链接
        /// </summary>
        /// <param name="path">文件路径例如:20190529\6843a10a-c21c-47f8-82dd-0ed3e77a2eff.png</param>
        /// <returns></returns>
        public string GetLink(string path)
        {
            #region 非office文件类不需要在线预览链接,直接返回参数
            var fileExtension = Path.GetExtension(path);
            if (".png;.jpg;.jpeg;.gif;.txt".Contains(fileExtension.ToLower()))
            {
                return(path);
            }
            #endregion

            #region 获取office文件在线预览链接
            WOPI wopi = new WOPI(service);
            //var config = service.GetDicItemsByCode("FileServer");
            var fileserver      = _dictionaryContext[SettingType.FileServer, SettingVariable.FileServerPath];           // config.First(f => f.Name == "FileServerPath").Value;
            var account         = _dictionaryContext[SettingType.FileServer, SettingVariable.Account];                  // config.First(f => f.Name == "Account").Value;
            var password        = _dictionaryContext[SettingType.FileServer, SettingVariable.Password];                 // config.First(f => f.Name == "Password").Value;
            var kstarFormWebURL = _dictionaryContext[SettingType.EnvironmentVariable, SettingVariable.KStarFormWebURL]; // config.First(f => f.Name == "KstarFormWebURL").Value;
            if (!ConnectFileServerHelp.ConnectFileServer(fileserver, account, password))
            {
                throw new Exception("连接文件服务器失败");
            }

            var filePath = fileserver + "\\" + path;

            //"http://*****:*****@"/wopi/files";
            return(wopi.GetLink(filePath, url));

            #endregion
        }
コード例 #2
0
 /// <summary>
 /// 校验时效获取文件数据流
 /// </summary>
 /// <param name="guid">与获取文件路径中的文件名称一致</param>
 /// <param name="path"></param>
 /// <param name="access_token"></param>
 /// <returns></returns>
 public FileStreamResult GetFile(Guid guid, string path, string access_token)
 {
     try
     {
         string name = Path.GetFileName(path);
         WOPI   wopi = new WOPI(service);
         if (!wopi.Validate(name, access_token))
         {
             var stream = new MemoryStream(UTF8Encoding.Default.GetBytes(""));
             return(File(stream, "application/octet-stream"));
         }
         //var config = service.GetDicItemsByCode("FileServer");
         var fileserver = _dictionaryContext[SettingType.FileServer, SettingVariable.FileServerPath]; // config.First(f => f.Name == "FileServerPath").Value;
         var account    = _dictionaryContext[SettingType.FileServer, SettingVariable.Account];        // config.First(f => f.Name == "Account").Value;
         var password   = _dictionaryContext[SettingType.FileServer, SettingVariable.Password];       // config.First(f => f.Name == "Password").Value;
         if (ConnectFileServerHelp.ConnectFileServer(fileserver, account, password))
         {
             var stream      = new FileStream(path, FileMode.Open);
             var contentType = MimeMapping.GetMimeMapping(path);
             return(File(stream, contentType));
         }
         else
         {
             throw new Exception("连接文件服务器失败");
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #3
0
        public ActionResult PreviewOnline(string path)
        {
            var  temp       = PartialView("~/Areas/Portal/Views/PreviewOnline.cshtml");
            WOPI wopi       = new WOPI(service);
            var  fileserver = _dictionaryContext[SettingType.FileServer, SettingVariable.FileServerPath];
            var  account    = _dictionaryContext[SettingType.FileServer, SettingVariable.Account];
            var  password   = _dictionaryContext[SettingType.FileServer, SettingVariable.Password];

            //连接不上报错
            if (!ConnectFileServerHelp.ConnectFileServer(fileserver, account, password))
            {
                throw new Exception("连接文件服务器失败");
            }
            var filePath      = fileserver + "\\" + path;
            var fileExtension = Path.GetExtension(path);

            if (".png;.jpg;.jpeg;.gif".Contains(fileExtension.ToLower()))
            {
                FileResponse(filePath, "image" + fileExtension.Replace(".", "/"));
                return(temp);
            }
            if (".txt".Contains(fileExtension.ToLower()))
            {
                FileResponse(filePath, "text/plain");
                return(temp);
            }

            HttpContext.Response.Write(@"<iframe src='" + path + "' frameborder='0' scrolling='no' id='external-frame'  style='height:100%; width:100%; margin-top: -7px;'></iframe>");
            return(temp);
        }
コード例 #4
0
        /// <summary>
        /// 获取文件信息
        /// </summary>
        /// <param name="guid">与获取文件路径中的文件名称一致</param>
        /// <param name="path"></param>
        /// <param name="access_token"></param>
        /// <returns></returns>
        public JsonResult GetFileInfo(Guid guid, string path, string access_token)
        {
            string name = Path.GetFileName(path);
            WOPI   wopi = new WOPI(service);

            if (!wopi.Validate(name, access_token))
            {
                return(Json(new CheckFileInfo(), JsonRequestBehavior.AllowGet));
            }

            var fileInfo = wopi.GetFileInfo(path);

            fileInfo.SupportsUpdate = false;
            fileInfo.UserCanWrite   = false;
            fileInfo.SupportsLocks  = false;

            return(Json(fileInfo, JsonRequestBehavior.AllowGet));
        }