10-10-2016 02:57 AM
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"
10-10-2016 04:04 AM
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);
10-10-2016 03:44 AM
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.
10-10-2016 04:04 AM
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);
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.