cancel
Showing results for 
Search instead for 
Did you mean: 

How to upload document on user created folder using dotcmis dll

shivtechno
Champ in-the-making
Champ in-the-making

I am trying to upload file on custom created folder by user or shared folder in alfresco but every time while uploading document it goes and upload on root  folder how can i change

folder or i can upload folder by object id of folder using dotcmis folder.

      Dictionary<string, string> parameters = new Dictionary<string, string>();

                    parameters[DotCMIS.SessionParameter.BindingType] = BindingType.AtomPub;

                    parameters[DotCMIS.SessionParameter.AtomPubUrl] = "http://127.0.0.1:8080/alfresco/api/-default-/public/cmis/versions/1.0/atom";

                    parameters[DotCMIS.SessionParameter.User] = UserName;

                    parameters[DotCMIS.SessionParameter.Password] = Password;

                    parameters[DotCMIS.SessionParameter.RepositoryId] = selectedValue; // Repository id of Custom Created Folder .....

                    SessionFactory factory = SessionFactory.NewInstance();

                    ISession session = factory.GetRepositories(parameters)[0].CreateSession();

                     IOperationContext oc = session.CreateOperationContext();

                    oc.IncludeAcls = true;

                    IFolder folder = session.GetRootFolder();

                    // document name

                    string formattedName = file.FileName;

                    // define dictionary

                    IDictionary<string, object> properties = new Dictionary<string, object>();

                    properties.Add(PropertyIds.Name, formattedName);

                    // define object type as document, as we wanted to create document

                    properties.Add(PropertyIds.ObjectTypeId, "cmis:document");//"cmis:document"

1 ACCEPTED ANSWER

kaynezhang
World-Class Innovator
World-Class Innovator

Use session.GetObjectByPath() or session.GetObject to get the IFolder object ,and use CreateDocument mehtod of IFolder to upload document to that folder,

for exmple using GetObjectByPath()

  IFolder folder1 = (IFolder)session.GetObjectByPath("/TESTFOLDER1");

  Dictionary<string, object> properties = new Dictionary<string, object>();

  properties[PropertyIds.ObjectTypeId] = "cmis:document";

  ContentStream contentStream = new ContentStream();

  FileStream fs = new FileStream("D:\\*****.pdf", FileMode.Open, FileAccess.Read);

  contentStream.Stream = fs;

  VersioningState vs = VersioningState.Major;

  ........

  folder1.CreateDocument(properties, contentStream, vs);

View answer in original post

2 REPLIES 2

mitpatoliya
Star Collaborator
Star Collaborator

Repository id refers to that Alfresco repository instance id. It is not for particular folder within alfresco.  For instance if you have two different instance of Alfresco repository running you can point to specific repo just by changing this id.  Each repository has their own unique repository id.

In code I see you are accessing root folder

IFolder folder = session.GetRootFolder();

You must be using that folder while uploading file as a destination location. Seems like you have not posted full code.

kaynezhang
World-Class Innovator
World-Class Innovator

Use session.GetObjectByPath() or session.GetObject to get the IFolder object ,and use CreateDocument mehtod of IFolder to upload document to that folder,

for exmple using GetObjectByPath()

  IFolder folder1 = (IFolder)session.GetObjectByPath("/TESTFOLDER1");

  Dictionary<string, object> properties = new Dictionary<string, object>();

  properties[PropertyIds.ObjectTypeId] = "cmis:document";

  ContentStream contentStream = new ContentStream();

  FileStream fs = new FileStream("D:\\*****.pdf", FileMode.Open, FileAccess.Read);

  contentStream.Stream = fs;

  VersioningState vs = VersioningState.Major;

  ........

  folder1.CreateDocument(properties, contentStream, vs);