Exemple #1
0
        /// <summary>
        /// Uses the MIMETypes class to match extensions to known MimeTypes from Guidewire. If changes are made to the document name, the new document URL is returned
        /// </summary>
        /// <param name="documentUrl">The URL of the document to resolve</param>
        /// <param name="mimeType">The MimeType as it exists in ClaimCenter</param>
        /// <returns></returns>
        public static String ResolveMissingExtension(string documentUrl, string mimeType)
        {
            List <string> extension = new List <string>();
            string        newDocUrl = documentUrl;

            //if (Path.HasExtension(newDocUrl)) return newDocUrl;

            // Get the list of known mime types/extensions
            using (MIMETypes mimetypes = new MIMETypes())
            {
                if (mimetypes.ContainsMimetype(mimeType))
                {
                    extension = mimetypes.ExtensionMapping[mimeType];
                }
            }

            // Update the file in SharePoint if no matching extensions were found, or if the mimetype wasn't unknown
            // (mimetypes of unknown should be left alone, Guidewire doesn't know what they are, and we should leave it up to SharePoint to figure out what the file is)
            if (extension.Count > 0 || !extension.Contains("unknown"))
            {
                try
                {
                    using (SPWeb shellWeb = SPContext.Current.Web)
                    {
                        SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            using (SPSite site = new SPSite(shellWeb.Site.Url))
                            {
                                using (SPWeb web = site.OpenWeb())
                                {
                                    web.AllowUnsafeUpdates = true;
                                    SPListItem item        = web.GetListItem(documentUrl);
                                    // Bypass the record if needed to, and use the MoveTo method to rename the document
                                    Records.BypassLocks(item, delegate(SPListItem bypassItem)
                                    {
                                        bypassItem.File.MoveTo((documentUrl + extension.First()), true);
                                    });
                                    newDocUrl = documentUrl + extension.First();
                                    web.AllowUnsafeUpdates = false;
                                }
                            }
                        });
                    }
                }
                catch (Exception e)
                {
                    Util.LogError("Adding an extension to the document {1} failed with exception: " + e.Message);
                }
            }

            return(newDocUrl);
        }
Exemple #2
0
        /// <summary>
        /// Gets the URL to a document. MimeType is used to assemble a URL that is compatible with Guidewire
        /// </summary>
        /// <param name="documentId">The document ID to get the URL for</param>
        /// <param name="mimeType">The MimeType as it is represented in ClaimCenter</param>
        /// <returns></returns>
        public GetDocumentUrlResult GetDocumentUrl(string documentId, string mimeType)
        {
            GetDocumentUrlResult result = GetDocumentUrl(documentId);

            if (result.Success)
            {
                // Check the extension of the document, and do additional processing if the extension is missing, contains a space or doesn't match a known extension from ClaimCenter
                string currentExtension = Path.GetExtension(result.DocumentUrl);
                using (MIMETypes mimeTypes = new MIMETypes())
                {
                    if (string.IsNullOrEmpty(currentExtension) || currentExtension.Contains(" "))
                    {
                        //Document doesn't have an extension.  Resolve this before attempting to access it.
                        result.DocumentUrl = Util.ResolveMissingExtension(result.DocumentUrl, mimeType);
                    }
                }
            }
            return(result);
        }