Example #1
0
        private FileAtts CreateFileAttsFromFileInfo(FileInfo fileInfo)
        {
            FileAtts fileAtts = new FileAtts();

            fileAtts.CreatedDate  = fileInfo.CreationTime;
            fileAtts.FileName     = fileInfo.Name;
            fileAtts.FileSize     = fileInfo.Length;
            fileAtts.ModifiedDate = fileInfo.LastWriteTime;

            return(fileAtts);
        }
Example #2
0
        internal void AddVersion(int nodeID, FileInfo fileInfo)
        {
            FileAtts fileAtts = CreateFileAttsFromFileInfo(fileInfo);

            Stream stream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read);

            ReAuthenticateIfRequired();
            String contextID = fDocManService.AddVersionContext(ref fDocsAuthentication, nodeID, null);

            UpdateAuthenticationTokens(fDocsAuthentication.AuthenticationToken);

            String objectID = fContentService.UploadContent(ref fContentAuthentication, contextID, fileAtts, stream);

            UpdateAuthenticationTokens(fContentAuthentication.AuthenticationToken);
        }
Example #3
0
        internal Node CreateNodeAndVersion(Node node, FileInfo fileInfo)
        {
            FileAtts fileAtts = CreateFileAttsFromFileInfo(fileInfo);

            Stream stream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read);

            // Create the node and add the version info at the same time
            ReAuthenticateIfRequired();
            String contextID = fDocManService.CreateNodeAndVersionContext(ref fDocsAuthentication, node);

            UpdateAuthenticationTokens(fDocsAuthentication.AuthenticationToken);

            String newNodeID = fContentService.UploadContent(ref fContentAuthentication, contextID, fileAtts, stream);

            UpdateAuthenticationTokens(fContentAuthentication.AuthenticationToken);

            // Reauthenticate in case the upload took a long time...
            ReAuthenticateIfRequired();
            Node newNode = fDocManService.GetNode(ref fDocsAuthentication, Int32.Parse(newNodeID));

            UpdateAuthenticationTokens(fDocsAuthentication.AuthenticationToken);

            return(newNode);
        }
 private long UploadFile(long parentId, string path,DoWorkEventArgs e)
 {
     if (_worker.CancellationPending){ e.Cancel = true;
         return -1;
     }
     ContentServiceClient contentService=new ContentServiceClient();
     DocumentManagementClient docMan = new DocumentManagementClient();
     FileInfo info = new FileInfo(path);
     _worker.ReportProgress(_counter, new {CurrentFile=info.Name});
     FileAtts fileAtts = new FileAtts
     {
         CreatedDate = info.CreationTime,
         FileName = info.Name,
         FileSize = info.Length,
         ModifiedDate = info.LastWriteTime
     };
     var stream = new FileStream(path,FileMode.Open,FileAccess.Read,FileShare.Read);
     ProgressStream pStream = new ProgressStream(stream);
     pStream.ProgressChanged += pStream_ProgressChanged;
     try
     {
         bool isVersionAdded = false;
         var res =
             docMan.GetNodeByName(ref _otAuthentication, parentId,
                 info.Name);
         string contextId;
         if (res == null)
         {
             contextId=docMan.CreateDocumentContext(ref _otAuthentication, parentId, info.Name, null,
                 false, null);
         }
         else
         {
             contextId = docMan.AddVersionContext(ref _otAuthentication, res.ID, null);
             isVersionAdded = true;
         }
         var id = contentService.UploadContent(ref _otAuthentication, contextId, fileAtts, pStream);
         ++_counter;
         _worker.ReportProgress(_counter,new {Message=isVersionAdded
                 ? string.Format("{{{0}}} - Version {1} added.", id, info.Name)
                 : string.Format("{{{0}}} - Document {1} added.", id, info.Name)});
     }
     catch (Exception ex)
     {
         _worker.ReportProgress(_counter, new {Message=ex.ToString()});
     }
     finally
     {
         contentService.Close();
         docMan.Close();
         stream.Close();
     }
     return -1;
 }