CREATE A NEW DOCUMENT VERSION GIVE CONFLICT

cancel
Showing results for 
Search instead for 
Did you mean: 
abfrank
Member II

CREATE A NEW DOCUMENT VERSION GIVE CONFLICT

Hello, am trying to create a document version on alfresco using c#, but i keep on getting conflict error. bellow is my 

private bool ConnectingUsingAtomPub_CreateDocumentNewVersion(string documentname, string retireefoldername, HttpPostedFileBase uploadedfile,string docID,string CheckInComment)
{
try
{

bool foldercreated = false;
// define dictonary with key value pair
Dictionary<string, string> parameters = new Dictionary<string, string>();

// define binding type, in our example we are using ATOMPUB as stated above
parameters[DotCMIS.SessionParameter.BindingType] = BindingType.AtomPub;

// define CMIS available path which is already available under alfresco
parameters[DotCMIS.SessionParameter.AtomPubUrl] = "http://localhost:8080/alfresco/cmisatom";

// alfresco portal admin user name
parameters[DotCMIS.SessionParameter.User] = "admin";

// alfresco portal admin password
parameters[DotCMIS.SessionParameter.Password] = "root";

// define session factory
SessionFactory factory = SessionFactory.NewInstance();

// using session factory get the default repository, on this repository we would be performing actions & create session on this repository
ISession session = factory.GetRepositories(parameters)[0].CreateSession();

// get the root folder in which we would be creating a new folder
IFolder rootfolder = session.GetRootFolder();


IItemEnumerable<ICmisObject> rootchildrens = rootfolder.GetChildren();

ICmisObject tstdoc = rootchildrens.Where(a => a.Name.ToLower() == "pension").FirstOrDefault();

IFolder Pesionfolder = tstdoc as IFolder;

IItemEnumerable<ICmisObject> pensionfolderchildrens = Pesionfolder.GetChildren();

ICmisObject theretireeIcm = pensionfolderchildrens.Where(a => a.Name.ToLower() == retireefoldername.ToLower()).FirstOrDefault();

IFolder retireefolder = theretireeIcm as IFolder;

// define dictionary

Document doc = ((Document)session.GetObject(docID));


// Document doc = ((Document)session.GetObject("workspace://SpacesStore/c38e8efa-04dd-46e1-938c-a20884dff5ee"));
string objId = string.Empty;
Document pwc=null;
try
{

// checkout the doc
IObjectId Iobj = doc.CheckOut();
objId = Iobj.Id;
pwc = (Document)session.GetObject(Iobj);
// Response.Write("Checked out doc ID: " + objId);
}
catch (Exception cbe)
{
// cancel the checkout incase of exception
doc.CancelCheckOut();
// Response.Write("Exception checking out; must be checked out already: " + cbe.Message);
}

// string versionlbl = "V"+(Convert.ToInt32(doc.VersionLabel)+0.1).ToString();
string lblvv = doc.VersionLabel;
// document name
// int inxex = documentname.IndexOf(".pdf");
string versionlbl = "V2.0";
string formattedName = versionlbl+"_"+documentname;
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");
properties.Add(PropertyIds.ObjectId, objId);

BinaryReader rdr = new BinaryReader(uploadedfile.InputStream);
byte[] imageByte = rdr.ReadBytes((int)uploadedfile.ContentLength);

// read a empty document with empty bytes
// fileUpload1: is a .net file upload control
ContentStream contentStream = new ContentStream
{
FileName = formattedName,
//MimeType = "application/msword",
MimeType = "application/pdf",
Length = uploadedfile.InputStream.Length,
Stream = new MemoryStream(imageByte)
};


retireefolder.CreateDocument(properties, contentStream, DotCMIS.Enums.VersioningState.CheckedOut);
IObjectId ob = pwc.CheckIn(true, properties, null, CheckInComment);


//IObjectId ob = doc.CheckIn(true, null, null, CheckInComment);
//addveriosn = doc.VersionLabel;
Document docd = (Document)session.GetObject(ob);
// Document newv = (Document)session.GetLatestDocumentVersion(ob);
return true;



}
catch (Exception ex)
{
return false;