public IList Write(IList content)
        {
            if (!_isBinary)
            {
                foreach (string str in content)
                {
                    _streamWriter.WriteLine(str);
                }
            }
            else
            {
                foreach (var obj in content)
                {
                    if (obj is byte)
                    {
                        _stream.WriteByte((byte)obj);
                    }
                    else if (obj is char)
                    {
                        _stream.WriteByte(Convert.ToByte((char)obj));
                    }
                }
            }

            _streamWriter.Flush();
            _stream.Position = 0;
#if PNPPSCORE
            _file.SaveBinary(new FileSaveBinaryInformation());
#else
            File.SaveBinaryDirect((_file.Context as ClientContext), _file.ServerRelativeUrl, _stream, true);
#endif
            return(content);
        }
示例#2
0
        public IList Write(IList content)
        {
            if (!_isBinary)
            {
                foreach (string str in content)
                {
                    _streamWriter.WriteLine(str);
                }
            }
            else
            {
                foreach (var obj in content)
                {
                    if (obj is byte)
                    {
                        _stream.WriteByte((byte)obj);
                    }
                    else if (obj is char)
                    {
                        _stream.WriteByte(Convert.ToByte((char)obj));
                    }
                }
            }

            _streamWriter.Flush();
            _stream.Position = 0;
            _file.SaveBinary(new FileSaveBinaryInformation());
            return(content);
        }
示例#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);
        }