예제 #1
0
        public string WebUrlFromPageUrl(string pageUrl)
        {
            // ie: pageurl:  http://localhost/Root/Sites/Default_Site/workspaces/Document/mydocumentws/Document_Library/my.doc
            // result: http://localhost/Root/Sites/Default_Site/workspaces/Document/mydocumentws

            // get root-relative url
            var hostIdx      = pageUrl.IndexOf(HttpContext.Current.Request.Url.Host);
            var prefixLength = hostIdx + HttpContext.Current.Request.Url.Host.Length;
            var path         = HttpUtility.UrlDecode(pageUrl.Substring(prefixLength));

            var rootIdx = pageUrl.ToLower().IndexOf("/root");

            if (rootIdx == -1)
            {
                // host selected in open dialog of office and navigated to doclibrary folder -> /Root is missing
                // ie: path:  /Sites/Default_Site/workspaces/Document/mydocumentws/Document_Library/my.doc
                if (path.ToLower().StartsWith("/sites"))
                {
                    path = RepositoryPath.Combine("/Root", path);
                }
                else
                {
                    path = RepositoryPath.Combine(PortalContext.Current.Site.Path, path);
                }
            }

            // searching starts from parentpath
            path = RepositoryPath.GetParentPath(path);
            var node = Node.LoadNode(path);
            var url  = string.Empty;

            if (node != null)
            {
                var ws = Workspace.GetWorkspaceForNode(node);
                if (ws != null)
                {
                    url = string.Concat(pageUrl.Substring(0, prefixLength), ws.Path);
                }
                else
                {
                    // workspace not found, it should be parent doclibrary's parent
                    var doclib = DwsHelper.GetDocumentLibraryForNode(node);
                    if (doclib != null)
                    {
                        url = string.Concat(pageUrl.Substring(0, prefixLength), doclib.ParentPath);
                    }
                    else
                    {
                        // standalone document, return parentpath
                        url = string.Concat(pageUrl.Substring(0, prefixLength), node.ParentPath);
                    }
                }
            }

            return(String.Concat(url));
        }
예제 #2
0
        private void HandleUrlToWebUrl(HttpContext context)
        {
            var path = context.Request.Form["url"];

            var weburl  = path;
            var fileurl = string.Empty;

            // ie.: /Sites or /Sites/Default_Site/workspace/Document/myws/Document_Library/mydoc.docx
            if (path != "/")
            {
                path   = DwsHelper.GetFullPath(path);
                weburl = path;

                var node = Node.LoadNode(path);
                if (node == null)
                {
                    node = Node.LoadNode(RepositoryPath.GetParentPath(path));
                }

                // searching starts from parentpath
                if (node != null)
                {
                    var doclib = DwsHelper.GetDocumentLibraryForNode(node);
                    if (doclib != null)
                    {
                        // weburl should be doclibs parent (most of the time currentworkspace)
                        // fileurl should be doclib name and doclib relative path
                        // this will work for /Sites/MySite/Doclib/document.docx, for /Sites/Mysite/myworkspace/Doclib/document.docx and for /Root/Doclib/document.docx
                        weburl  = doclib.ParentPath;
                        fileurl = (path.Length > doclib.ParentPath.Length) ? path.Substring(doclib.ParentPath.Length + 1) : string.Empty;
                    }
                    else
                    {
                        // weburl should be parent's parentpath
                        // fileurl should be parentname + name  -> parent will act as a mocked document library
                        // this will work for /Root/YourDocuments/document.docx
                        if (node.Parent != null)
                        {
                            weburl  = node.Parent.ParentPath;
                            fileurl = RepositoryPath.Combine(node.Parent.Name, node.Name);
                        }
                    }
                }
            }

            var responseStr = GetFormattedString(string.Format(URLTOWEBURLSTR, weburl, fileurl));

            context.Response.Charset     = "";
            context.Response.ContentType = "application/x-vermeer-rpc";
            context.Response.AddHeader("Content-Length", responseStr.Length.ToString());
            context.Response.Write(responseStr);
            context.Response.Flush();
            context.Response.End();
        }
예제 #3
0
        private static string GetDocInfo(Node doc)
        {
            var doclib = DwsHelper.GetDocumentLibraryForNode(doc);
            var name   = doc.Name;

            // name should be documentLibrary/x.docx
            if (doclib != null)
            {
                name = doc.Path.Substring(doclib.Parent.Path.Length + 1);
            }

            var metainfo = GetDocMetaInfo(doc);
            var dinfo    = string.Format(GETDOCSMETAINFODOCUMENTSTR, name, metainfo);

            return(dinfo);
        }