Example #1
0
        public PutRelativeFile Put_Relative(int accessTokenId)
        {
            var result = new PutRelativeFile();

            var token = _tokenManager.GetToken(accessTokenId);

            var newFilePath = string.Empty;

            var target = Request.Headers.Contains("X-WOPI-RelativeTarget") ? Request.Headers.GetValues("X-WOPI-RelativeTarget").First() : Request.Headers.GetValues("X-WOPI-SuggestedTarget").First();

            bool overwrite = Request.Headers.Contains("X-WOPI-RelativeTarget") && Convert.ToBoolean(Request.Headers.GetValues("X-WOPI-OverwriteRelativeTarget").First());

            if (string.IsNullOrEmpty(target))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            if (target.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries).Count() > 1)
            {
                var fileName = Path.GetFileName(token.FilePath);

                newFilePath = token.FilePath.ReplaceLast(fileName, target);
            }
            else
            {
                newFilePath = Path.ChangeExtension(token.FilePath, target);
            }

            if (overwrite == false && _webDavManager.FileExist(newFilePath))
            {
                throw new HttpResponseException(HttpStatusCode.Conflict);
            }

            var bytes = Request.Content.ReadAsByteArrayAsync().Result;

            _webDavManager.UploadFile(newFilePath, bytes);

            var newToken = _tokenManager.CreateToken(WspContext.User, newFilePath);

            var readUrlPart  = Url.Route(FileSystemRouteNames.ViewOfficeOnline, new { org = WspContext.User.OrganizationId, pathPart = newFilePath });
            var writeUrlPart = Url.Route(FileSystemRouteNames.EditOfficeOnline, new { org = WspContext.User.OrganizationId, pathPart = newFilePath });

            result.HostEditUrl = new Uri(Request.RequestUri, writeUrlPart).ToString();
            result.HostViewUrl = new Uri(Request.RequestUri, readUrlPart).ToString();;
            result.Name        = Path.GetFileName(newFilePath);
            result.Url         = Url.GenerateWopiUrl(newToken, newFilePath);

            return(result);
        }
Example #2
0
        public ActionResult ShowOfficeDocument(string org, string pathPart, string owaOpenerUri)
        {
            string fileUrl     = WebDavAppConfigManager.Instance.WebdavRoot + org + "/" + pathPart.TrimStart('/');
            var    accessToken = _tokenManager.CreateToken(WspContext.User, pathPart);

            var urlPart = Url.HttpRouteUrl(OwaRouteNames.CheckFileInfo, new { accessTokenId = accessToken.Id });
            var url     = new Uri(Request.Url, urlPart).ToString();

            string wopiSrc = Server.UrlDecode(url);

            var uri = string.Format("{0}/{1}WOPISrc={2}&access_token={3}", WebDavAppConfigManager.Instance.OfficeOnline.Url, owaOpenerUri, Server.UrlEncode(wopiSrc), Server.UrlEncode(accessToken.AccessToken.ToString("N")));

            string fileName = fileUrl.Split('/').Last();
            string folder   = pathPart.ReplaceLast(fileName, "").Trim('/');

            return(View("ShowOfficeDocument", new OfficeOnlineModel(uri, fileName, folder)));
        }