当前位置: 首页>>代码示例>>C#>>正文


C# IFolder.CreateDocument方法代码示例

本文整理汇总了C#中IFolder.CreateDocument方法的典型用法代码示例。如果您正苦于以下问题:C# IFolder.CreateDocument方法的具体用法?C# IFolder.CreateDocument怎么用?C# IFolder.CreateDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IFolder的用法示例。


在下文中一共展示了IFolder.CreateDocument方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UploadRandomDocumentTo

        private static void UploadRandomDocumentTo(IFolder folder)
        {
            string filename = "file_" + Guid.NewGuid() + ".bin";

            //byte[] content = UTF8Encoding.UTF8.GetBytes("Hello World!");
            int sizeInMb = 40;
            byte[] data = new byte[sizeInMb * 1024 * 1024];
            Random rng = new Random();
            rng.NextBytes(data);

            IDictionary<string, object> properties = new Dictionary<string, object>();
            properties[PropertyIds.Name] = filename;
            properties[PropertyIds.ObjectTypeId] = "cmis:document";

            ContentStream contentStream = new ContentStream();
            contentStream.FileName = filename;
            contentStream.MimeType = "application/octet-stream";
            contentStream.Length = data.Length;
            contentStream.Stream = new MemoryStream(data);

            Console.Write("Uploading " + filename + " ... ");
            folder.CreateDocument(properties, contentStream, null);
            Console.WriteLine(" Done.");

            contentStream.Stream.Close();
            contentStream.Stream.Dispose();
        }
开发者ID:nicolas-raoul,项目名称:dotcmis-upload,代码行数:27,代码来源:Program.cs

示例2: Upload

        private IDocument Upload(IFolder uploadFolder, MakuraDocument document)
        {
            var cmisDocumentStream = document.ContentStream.ConvertCmis();
            var existDoc = uploadFolder.GetChildren().OfType<IDocument>().FirstOrDefault(p => p.Name == document.Name);

            if (existDoc == null) {
                var properties = new Dictionary<string, object>();
                properties[PropertyIds.Name] = document.Name;
                properties[PropertyIds.ObjectTypeId] = "cmis:document";

                return uploadFolder.CreateDocument(properties, cmisDocumentStream, DotCMIS.Enums.VersioningState.Minor);
            } else {
                existDoc.SetContentStream(cmisDocumentStream,true);
                return existDoc;
            }
        }
开发者ID:sixpetals,项目名称:CmisActionAgent,代码行数:16,代码来源:CmisUploadAction.cs

示例3: UploadFile

        /**
         * Upload a single file to the CMIS server.
         */
        private void UploadFile(string filePath, IFolder remoteFolder)
        {
            activityListener.ActivityStarted();
            IDocument remoteDocument = null;
            try
            {
                // Prepare properties
                string fileName = Path.GetFileName(filePath);
                Dictionary<string, object> properties = new Dictionary<string, object>();
                properties.Add(PropertyIds.Name, fileName);
                properties.Add(PropertyIds.ObjectTypeId, "cmis:document");

                // Prepare content stream
                ContentStream contentStream = new ContentStream();
                contentStream.FileName = fileName;
                contentStream.MimeType = MimeType.GetMIMEType(fileName); // Should CmisSync try to guess?
                contentStream.Stream = File.OpenRead(filePath);

                // Upload
                remoteDocument = remoteFolder.CreateDocument(properties, contentStream, null);

                // Create database entry for this file.
                database.AddFile(filePath, remoteDocument.LastModificationDate, null);
            }
            catch (FileNotFoundException e)
            {
                SparkleLogger.LogInfo("Sync", "File deleted while trying to upload it, reverting.");
                // File has been deleted while we were trying to upload/checksum/add.
                // This can typically happen in Windows when creating a new text file and giving it a name.
                // Revert the upload.
                if (remoteDocument != null)
                {
                    remoteDocument.DeleteAllVersions();
                }
            }
            activityListener.ActivityStopped();
        }
开发者ID:smcardle,项目名称:CmisSync,代码行数:40,代码来源:CmisDirectory.cs

示例4: UploadFile

            /// <summary>
            /// Upload a single file to the CMIS server.
            /// </summary>
            private bool UploadFile(string filePath, IFolder remoteFolder) // TODO make SyncItem
            {
                SleepWhileSuspended();

                var syncItem = database.GetSyncItemFromLocalPath(filePath);
                if (null == syncItem)
                {
                    syncItem = SyncItemFactory.CreateFromLocalPath(filePath, repoinfo);
                }
                Logger.Info("Uploading: " + syncItem.LocalPath);

                try
                {
                    IDocument remoteDocument = null;
                    byte[] filehash = { };

                    // Prepare properties
                    string remoteFileName = syncItem.RemoteFileName;
                    Dictionary<string, object> properties = new Dictionary<string, object>();
                    properties.Add(PropertyIds.Name, remoteFileName);
                    properties.Add(PropertyIds.ObjectTypeId, "cmis:document");
                    properties.Add(PropertyIds.CreationDate, File.GetCreationTime(syncItem.LocalPath));
                    properties.Add(PropertyIds.LastModificationDate, File.GetLastWriteTime(syncItem.LocalPath));

                    // Prepare content stream
                    using (Stream file = File.Open(syncItem.LocalPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    using (SHA1 hashAlg = new SHA1Managed())
                    using (CryptoStream hashstream = new CryptoStream(file, hashAlg, CryptoStreamMode.Read))
                    {
                        ContentStream contentStream = new ContentStream();
                        contentStream.FileName = remoteFileName;
                        contentStream.MimeType = MimeType.GetMIMEType(remoteFileName);
                        contentStream.Length = file.Length;
                        contentStream.Stream = hashstream;

                        Logger.Debug("Uploading: " + syncItem.LocalPath + " as "
                            + remoteFolder.Path + "/" + remoteFileName);
                        remoteDocument = remoteFolder.CreateDocument(properties, contentStream, null);
                        Logger.Debug("Uploaded: " + syncItem.LocalPath);
                        filehash = hashAlg.Hash;
                    }

                    // Get metadata. Some metadata has probably been automatically added by the server.
                    Dictionary<string, string[]> metadata = FetchMetadata(remoteDocument);

                    // Create database entry for this file.
                    database.AddFile(syncItem, remoteDocument.Id, remoteDocument.LastModificationDate, metadata, filehash);
                    Logger.Info("Added file to database: " + syncItem.LocalPath);
                    return true;
                }
                catch (Exception e)
                {
                    ProcessRecoverableException("Could not upload file: " + syncItem.LocalPath, e);
                    return false;
                }
            }
开发者ID:jelacote,项目名称:CmisSync,代码行数:59,代码来源:SynchronizedFolder.cs

示例5: CreateDocument

        public IDocument CreateDocument(IFolder folder, string name, string content)
        {
            Dictionary<string, object> properties = new Dictionary<string, object>();
            properties.Add(PropertyIds.Name, name);
            properties.Add(PropertyIds.ObjectTypeId, "cmis:document");

            ContentStream contentStream = new ContentStream();
            contentStream.FileName = name;
            contentStream.MimeType = MimeType.GetMIMEType(name);
            contentStream.Length = content.Length;
            contentStream.Stream = new MemoryStream(Encoding.UTF8.GetBytes(content));

            return folder.CreateDocument(properties, contentStream, null);
        }
开发者ID:pcreignou,项目名称:CmisSync,代码行数:14,代码来源:CmisSyncTests.cs

示例6: UploadFile

            /// <summary>
            /// Upload a single file to the CMIS server.
            /// </summary>
            private void UploadFile(string filePath, IFolder remoteFolder)
            {
                activityListener.ActivityStarted();
                IDocument remoteDocument = null;
                Boolean success = false;
                try
                {
                    Logger.Info("Uploading: " + filePath);

                    // Prepare properties
                    string fileName = Path.GetFileName(filePath);
                    Dictionary<string, object> properties = new Dictionary<string, object>();
                    properties.Add(PropertyIds.Name, fileName);
                    properties.Add(PropertyIds.ObjectTypeId, "cmis:document");

                    // Prepare content stream
                    using (Stream file = File.OpenRead(filePath))
                    {
                        ContentStream contentStream = new ContentStream();
                        contentStream.FileName = fileName;
                        contentStream.MimeType = MimeType.GetMIMEType(fileName);
                        contentStream.Length = file.Length;
                        contentStream.Stream = file;

                        // Upload
                        try
                        {
                            remoteDocument = remoteFolder.CreateDocument(properties, contentStream, null);
                            success = true;
                        }
                        catch (Exception ex)
                        {
                            Logger.Fatal("Upload failed: " + filePath + " " + ex);
                            if (contentStream != null) {
                                contentStream.Stream.Close();
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    if (e is FileNotFoundException ||
                        e is IOException)
                    {
                        Logger.Warn("File deleted while trying to upload it, reverting.");
                        // File has been deleted while we were trying to upload/checksum/add.
                        // This can typically happen in Windows Explore when creating a new text file and giving it a name.
                        // In this case, revert the upload.
                        if (remoteDocument != null)
                        {
                            remoteDocument.DeleteAllVersions();
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
                    
                // Metadata.
                if (success)
                {
                    Logger.Info("Uploaded: " + filePath);

                    // Get metadata. Some metadata has probably been automatically added by the server.
                    Dictionary<string, string[]> metadata = FetchMetadata(remoteDocument);

                    // Create database entry for this file.
                    database.AddFile(filePath, remoteDocument.LastModificationDate, metadata);
                }

                activityListener.ActivityStopped();
            }
开发者ID:jmanuelnavarro,项目名称:CmisSync,代码行数:76,代码来源:SynchronizedFolder.cs


注:本文中的IFolder.CreateDocument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。