Пример #1
0
 internal static void ProcessAppListItem(ClientContext clientContext, ListItem item)
 {
     if (null == clientContext)
     {
         throw new ArgumentNullException("clientContext");
     }
     if (null == item)
     {
         throw new ArgumentNullException("item");
     }
     try
     {
         Logger.Logger.LogInfo("Processing list item with ID {0}", () => {
             clientContext.Load(item.File);
             var stream = item.File.OpenBinaryStream();
             clientContext.ExecuteQuery();
             var fileInfo           = new FileSaveBinaryInformation();
             fileInfo.ContentStream = new System.IO.MemoryStream();
             // Load the app manifest file.
             ProcessManifest(stream.Value, fileInfo.ContentStream, (manifest, ns) => {
                 // Load the properties.
                 var propNode = manifest.SelectSingleNode("x:App/x:Properties", ns);
                 // Look for the endpoints.
                 var installedNode   = propNode.SelectSingleNode("x:InstalledEventEndpoint", ns);
                 var upgradedNode    = propNode.SelectSingleNode("x:UpgradedEventEndpoint", ns);
                 var uninstalledNode = propNode.SelectSingleNode("x:UninstallingEventEndpoint", ns);
                 if (null == installedNode)
                 {
                     installedNode = manifest.CreateElement("InstalledEventEndpoint", manifest.DocumentElement.NamespaceURI);
                     propNode.AppendChild(installedNode);
                 }
                 if (null == upgradedNode)
                 {
                     upgradedNode = manifest.CreateElement("UpgradedEventEndpoint", manifest.DocumentElement.NamespaceURI);
                     propNode.AppendChild(upgradedNode);
                 }
                 if (null == uninstalledNode)
                 {
                     uninstalledNode = manifest.CreateElement("UninstallingEventEndpoint", manifest.DocumentElement.NamespaceURI);
                     propNode.AppendChild(uninstalledNode);
                 }
                 // NOTE: We're replacing the app installing and upgrading events so we can manage app lifecycle.
                 // If the deployed originally used these events, we've overridden them.
                 installedNode.InnerText   = GetServiceUrl("AppMgmtReceiver.svc");
                 upgradedNode.InnerText    = GetServiceUrl("AppMgmtReceiver.svc");
                 uninstalledNode.InnerText = GetServiceUrl("AppMgmtReceiver.svc");
             });
             // Save the manifest back to SharePoint.
             fileInfo.ContentStream.Seek(0, System.IO.SeekOrigin.Begin);
             item.File.SaveBinary(fileInfo);
             clientContext.Load(item.File);
             clientContext.ExecuteQuery();
         }, item.Id);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.ToString());
         Logger.Logger.LogError(ex.ToString());
     }
 }
Пример #2
0
        public void UploadReplacementFile(byte[] content, bool checkRequiredFields, Dictionary <string, object> fieldValues)
        {
            FileSaveBinaryInformation fsbi = new FileSaveBinaryInformation();

            fsbi.CheckRequiredFields = checkRequiredFields;
            fsbi.FieldValues         = fieldValues;
            fsbi.Content             = content;
            fsbi.ETag = _file.ETag;
            _file.SaveBinary(fsbi);
            _file.Context.ExecuteQuery();
            Refresh();
        }
Пример #3
0
        /// <summary>
        /// Uploads the document to matter library.
        /// </summary>
        /// <param name="requestObject">Request Object containing SharePoint App Token</param>
        /// <param name="sourceUrl">URL of the source document</param>
        /// <param name="documentStream">Content stream of the document</param>
        /// <param name="versionInfo">The version information.</param>
        /// <param name="comments">The comments.</param>
        /// <param name="retainCheckOut">retain check out option</param>
        /// <returns>Content Type List for the Request Object containing SharePoint App Token</returns>
        internal static string UploadtoMatter(RequestObject requestObject, string sourceUrl, Stream documentStream, int versionInfo, string comments, bool retainCheckOut)
        {
            string status = ConstantStrings.FALSE;
            string result = ConstantStrings.FALSE;

            try
            {
                if (null != requestObject)
                {
                    ClientContext clientContext;
                    if (!string.IsNullOrWhiteSpace(sourceUrl) && null != documentStream)
                    {
                        string[] sourceUrlParts = sourceUrl.Split(Convert.ToChar(ConstantStrings.DOLLAR, CultureInfo.InvariantCulture));
                        if (2 == sourceUrlParts.Length)
                        {
                            using (clientContext = ServiceUtility.GetClientContext(requestObject.SPAppToken, new Uri(sourceUrlParts[0]), requestObject.RefreshToken))
                            {
                                Microsoft.SharePoint.Client.File file = clientContext.Web.GetFileByServerRelativeUrl(sourceUrlParts[1]);
                                string documentLibraryName            = BriefcaseHelperFunction.getLibraryName(clientContext, file);
                                string contentType = string.Empty;
                                contentType = BriefcaseContentTypeHelperFunctions.ContentTypeByName(requestObject, clientContext, file.Name, sourceUrl, 1, contentType, documentLibraryName);
                                string listContentType = BriefcaseContentTypeHelperFunctions.GetContentTypeList(requestObject, clientContext, sourceUrl, contentType, 1, documentLibraryName);
                                status = BriefcaseContentTypeHelperFunctions.GetContentTypeList(requestObject, clientContext, sourceUrl, contentType, 2, documentLibraryName);
                                FileSaveBinaryInformation fileSaveBinaryInformation = new FileSaveBinaryInformation();
                                fileSaveBinaryInformation.ContentStream = documentStream;
                                file.SaveBinary(fileSaveBinaryInformation);
                                // Check if file is already checked out
                                if (file.CheckOutType == CheckOutType.None)
                                {
                                    file.CheckOut();
                                }
                                // Check the type of Check in to be performed
                                switch (versionInfo)
                                {
                                case 0:
                                    file.CheckIn(comments, CheckinType.MinorCheckIn);
                                    break;

                                case 1:
                                    file.CheckIn(comments, CheckinType.MajorCheckIn);
                                    break;

                                case 2:
                                    file.CheckIn(comments, CheckinType.OverwriteCheckIn);
                                    break;
                                }
                                // Load the Stream data for the file
                                clientContext.ExecuteQuery();
                                status = BriefcaseContentTypeHelperFunctions.GetContentTypeList(requestObject, clientContext, sourceUrl, listContentType, 2, documentLibraryName);
                                // Check whether we need to retain checkout
                                if (retainCheckOut)
                                {
                                    file.CheckOut();
                                    clientContext.ExecuteQuery();
                                }
                                status = string.Concat(ConstantStrings.TRUE, ConstantStrings.Comma, ConstantStrings.Space, file.ServerRelativeUrl);
                            }
                        }
                        result = status;
                    }
                    else
                    {
                        status = string.Concat(ConstantStrings.FALSE, ConstantStrings.Comma, ConstantStrings.Space, TextConstants.MissingParametersMessage);
                        result = status;
                    }
                }
            }
            catch (Exception exception)
            {
                status = string.Concat(ConstantStrings.FALSE, ConstantStrings.Comma, ConstantStrings.Space, ServiceUtility.RemoveEscapeCharacter(exception.Message));
                result = status;
            }
            return(result);
        }
Пример #4
0
 protected override long SaveDocument(string LocalFilePath, DocumentStorage Storage, DocumentStorageArea StorageArea, Document Document, BindingList <DocumentAttributeValue> attributeValue)
 {
     try
     {
         byte[] data         = null;
         File   fileUploaded = null;
         //Pick up the file in binary stream
         data = Document.Content.Blob;
         //
         ClientContext context = new ClientContext(Storage.MainPath);
         context.Credentials = new NetworkCredential(Storage.AuthenticationKey, Storage.AuthenticationPassword);
         Web  web  = context.Web;
         List docs = web.Lists.GetByTitle(Storage.Name);
         context.ExecuteQuery();
         //
         Folder foolder = docs.RootFolder;
         if (!string.IsNullOrEmpty(StorageArea.Path))
         {
             try
             {
                 if ((foolder = docs.RootFolder.Folders.Where(x => x.Name == StorageArea.Path).FirstOrDefault()) == null)
                 {
                     docs.RootFolder.Folders.Add(StorageArea.Path);
                 }
             }
             catch (Exception)
             {
                 docs.RootFolder.Folders.Add(StorageArea.Path);
             }
         }
         context.ExecuteQuery();
         string fileName = GetIdDocuemnt(Document) + System.IO.Path.GetExtension(Document.Name);
         FileCreationInformation newFile = new FileCreationInformation();
         newFile.Content = data;
         newFile.Url     = fileName;
         try
         {
             IEnumerable <File> resultFiles = context.LoadQuery(foolder.Files.Where(x => x.Name == fileName).Include(x => x.ListItemAllFields));
             context.ExecuteQuery();
             fileUploaded = resultFiles.FirstOrDefault();
         }
         catch { }
         if (fileUploaded != null)
         {
             fileUploaded.CheckOut();
             context.ExecuteQuery();
             FileSaveBinaryInformation newFileInfo = new FileSaveBinaryInformation();
             newFileInfo.Content = data;
             fileUploaded.SaveBinary(newFileInfo);
             fileUploaded.CheckIn("BiblosDS", CheckinType.MajorCheckIn);
             context.ExecuteQuery();
             ListItem listItems = fileUploaded.ListItemAllFields;
             foreach (var item in Document.AttributeValues)
             {
                 listItems[item.Attribute.Name] = item.Value;
             }
             fileUploaded.ListItemAllFields.Update();
         }
         else
         {
             fileUploaded = foolder.Files.Add(newFile);
             ListItem listItems = fileUploaded.ListItemAllFields;
             foreach (var item in Document.AttributeValues)
             {
                 listItems[item.Attribute.Name] = item.Value;
             }
             fileUploaded.ListItemAllFields.Update();
         }
         //Set the file version
         context.ExecuteQuery();
         context.Load(fileUploaded, w => w.MajorVersion);
         context.ExecuteQuery();
         Document.StorageVersion = fileUploaded.MajorVersion;
         return(data.Length);
     }
     catch (Exception ex)
     {
         Logging.WriteLogEvent(LoggingSource.BiblosDS_WCF_Storage, "SaveDocument", ex.ToString(), LoggingOperationType.BiblosDS_InsertDocument, LoggingLevel.BiblosDS_Errors);
         throw;
     }
 }
Пример #5
0
 public void UploadReplacementFile(byte[] content, bool checkRequiredFields, Dictionary<string, object> fieldValues)
 {
     FileSaveBinaryInformation fsbi = new FileSaveBinaryInformation();
     fsbi.CheckRequiredFields = checkRequiredFields;
     fsbi.FieldValues = fieldValues;
     fsbi.Content = content;
     fsbi.ETag = _file.ETag;
     _file.SaveBinary(fsbi);
     _file.Context.ExecuteQuery();
     Refresh();
 }
 /// <summary>
 /// Uploads the document to matter library.
 /// </summary>
 /// <param name="requestObject">Request Object containing SharePoint App Token</param>
 /// <param name="sourceUrl">URL of the source document</param>
 /// <param name="documentStream">Content stream of the document</param>
 /// <param name="versionInfo">The version information.</param>
 /// <param name="comments">The comments.</param>
 /// <param name="retainCheckOut">retain check out option</param>
 /// <returns>Content Type List for the Request Object containing SharePoint App Token</returns>
 internal static string UploadtoMatter(RequestObject requestObject, string sourceUrl, Stream documentStream, int versionInfo, string comments, bool retainCheckOut)
 {
     string status = ConstantStrings.FALSE;
     string result = ConstantStrings.FALSE;
     try
     {
         if (null != requestObject)
         {
             ClientContext clientContext;
             if (!string.IsNullOrWhiteSpace(sourceUrl) && null != documentStream)
             {
                 string[] sourceUrlParts = sourceUrl.Split(Convert.ToChar(ConstantStrings.DOLLAR, CultureInfo.InvariantCulture));
                 if (2 == sourceUrlParts.Length)
                 {
                     using (clientContext = ServiceUtility.GetClientContext(requestObject.SPAppToken, new Uri(sourceUrlParts[0]), requestObject.RefreshToken))
                     {
                         Microsoft.SharePoint.Client.File file = clientContext.Web.GetFileByServerRelativeUrl(sourceUrlParts[1]);
                         string documentLibraryName = BriefcaseHelperFunction.getLibraryName(clientContext, file);
                         string contentType = string.Empty;
                         contentType = BriefcaseContentTypeHelperFunctions.ContentTypeByName(requestObject, clientContext, file.Name, sourceUrl, 1, contentType, documentLibraryName);
                         string listContentType = BriefcaseContentTypeHelperFunctions.GetContentTypeList(requestObject, clientContext, sourceUrl, contentType, 1, documentLibraryName);
                         status = BriefcaseContentTypeHelperFunctions.GetContentTypeList(requestObject, clientContext, sourceUrl, contentType, 2, documentLibraryName);
                         FileSaveBinaryInformation fileSaveBinaryInformation = new FileSaveBinaryInformation();
                         fileSaveBinaryInformation.ContentStream = documentStream;
                         file.SaveBinary(fileSaveBinaryInformation);
                         // Check if file is already checked out
                         if (file.CheckOutType == CheckOutType.None)
                         {
                             file.CheckOut();
                         }
                         // Check the type of Check in to be performed
                         switch (versionInfo)
                         {
                             case 0:
                                 file.CheckIn(comments, CheckinType.MinorCheckIn);
                                 break;
                             case 1:
                                 file.CheckIn(comments, CheckinType.MajorCheckIn);
                                 break;
                             case 2:
                                 file.CheckIn(comments, CheckinType.OverwriteCheckIn);
                                 break;
                         }
                         // Load the Stream data for the file                                                            
                         clientContext.ExecuteQuery();
                         status = BriefcaseContentTypeHelperFunctions.GetContentTypeList(requestObject, clientContext, sourceUrl, listContentType, 2, documentLibraryName);
                         // Check whether we need to retain checkout
                         if (retainCheckOut)
                         {
                             file.CheckOut();
                             clientContext.ExecuteQuery();
                         }
                         status = string.Concat(ConstantStrings.TRUE, ConstantStrings.Comma, ConstantStrings.Space, file.ServerRelativeUrl);
                     }
                 }
                 result = status;
             }
             else
             {
                 status = string.Concat(ConstantStrings.FALSE, ConstantStrings.Comma, ConstantStrings.Space, TextConstants.MissingParametersMessage);
                 result = status;
             }
         }
     }
     catch (Exception exception)
     {
         status = string.Concat(ConstantStrings.FALSE, ConstantStrings.Comma, ConstantStrings.Space, ServiceUtility.RemoveEscapeCharacter(exception.Message));
         result = status;
     }
     return result;
 }