Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
public string AssignCategory(string sessionID, string categoryID, string documentID, string[][] attributes)
{
try
{
docauth.AuthenticationToken = sessionID;
DocumentManagement.AttributeGroup[] attributegroups = new DocumentManagement.AttributeGroup[1];
DocumentManagement.DataValue[] datavalues = new DocumentManagement.DataValue[2];
DocumentManagement.AttributeGroup attributegroup = new DocumentManagement.AttributeGroup();
metadata = new DocumentManagement.Metadata();
DocumentManagement.Node n = new DocumentManagement.Node();
n = doc.GetNode(ref docauth, int.Parse(documentID));
DocumentManagement.AttributeGroupDefinition attgrdefinition = doc.GetCategoryDefinition(ref docauth, int.Parse(categoryID));
attributegroup = doc.GetAttributeGroupTemplate(ref docauth, attgrdefinition.Type, attgrdefinition.Key);
metadata.AttributeGroups = new DocumentManagement.AttributeGroup[1];
metadata.AttributeGroups.SetValue(attributegroup, 0);
datavalues = metadata.AttributeGroups[0].Values;
n.Metadata = GenerateMetadata(metadata, datavalues, ConvertArrayToList(attributes));
doc.UpdateNode(ref docauth, n);
}
catch (Exception ex)
{
return "";
}
return "1";
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; //for using the file info
/*HUGE DISCLAIMER
THIS DOCUMENT IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SAMPLE CODE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. BY USING THIS CODE YOU AGREE TO THE ABOVE TERMS.*/
//APPOOS AT HOTMAIL.COM FOR AHABAOUB USING 9.7.1 LIVELINK AND C# EXPRESS 2010 WITH
//[URL unfurl="true"]http://www.tek-tips.com/viewthread.cfm?qid=1684806[/URL]
//SYNOPSIS: WE START WITH A PRIV USER ADMIN/PASSWORD
//WE GET A AUTH TOKEN FOR THIS USER
//WE SET THAT ENCRYPTED COOKIE(TOKEN) INTO OUR DMOTAUTHENTICATION OBJECT
//USING THAT DMOTAUTH OBJECT WE IMPERSONATE A USER IMPUSER AND SET ITS TOKEN
//WE GET A TOKEN THIS IS THE IMP USER
//WE RESET THE DOCUMENTACCESS TOKEN WITH IT SO IT IS AS IF WE HAVE LOGGED ON IN AS THE IMPERSONATED USER
//READ THIS WITHOUT FAIL
//IF A NEWER WEBSVCS SUCH AS CS10 WEBSVCS ARE USED THEN YOU ARE SUPPOSED TO USE THE REF KEY WORK LIKE
////ref keyword to be used when dealing with CS10 webbsvcs
//string impUserToken = authClient.ImpersonateUser(ref impUser, "APPU");
//I CONVERETED A CS10 WEBSVCS CODE TO A 9.7.1 CODE AND I HAD TO COMMENT OUT ALL THE REF STUFF
//FINAL NOTE THIS WAS WRITTEN FOR AHABAOUB IN TEKTIPS HENCE THE FIRST PERSON CALL IN MANY PLACES
namespace AddDocWithCategory
{
class CreateFolderMoveFolder
{
private static Dictionary<int, string> timeZones = new Dictionary<int, string>();
static void Main(string[] args)
{
//==================================================================================
// 1) Create clients that use the service references
//==================================================================================
// TomCatServiceAuth.AuthenticationClient authClient = new TomCatServiceAuth.AuthenticationClient();
Authentication.AuthenticationClient authClient = new Authentication.AuthenticationClient();
Authentication.OTAuthentication impUser= new Authentication.OTAuthentication(); //for impersonating somebody
DocumentManagement.DocumentManagementClient dc = new DocumentManagement.DocumentManagementClient();
DocumentManagement.Metadata md = new DocumentManagement.Metadata();
//call and create clients if we were messing with workflow and users and groups
//we don't use it here but just as well if somebody asked how to work with workflow or users and groups
MemberService.MemberServiceClient ms=new MemberService.MemberServiceClient();
WorkflowService.WorkflowServiceClient ws = new WorkflowService.WorkflowServiceClient();
// 2) Authenticate with the Livelink Server and obtain an authentication token
//==================================================================================
DocumentManagement.OTAuthentication dmOTAuth = new DocumentManagement.OTAuthentication();
DocumentManagement.MoveOptions mo = new DocumentManagement.MoveOptions();
mo.AddVersion = true;
// mo.AttrSourceType=AddDocWithCategory.AttributeSourceType.ORIGINAL;//it is a ENUM
// mo.AttrSourceType = AddDocWithCategory.AttributeSourceType.DESTINATION;//it is a ENUM did not work
// mo.AttrSourceType = AddDocWithCategory.AttributeSourceType.MERGE;
// mo.ForceInheritPermissions = true;
//everything upto this point is on the client nothing really has happened till the next things are done.
//we have a livelink authenticated webserver at this point no IWA
try
{
string username = "livelink";
string password = "livelink";
//string token = authClient.AuthenticateUser(username, password);
string token = authClient.AuthenticateUser(username, password);
if (token != null)
{
//ESENTIALLY WE GET A DATABASE CONNECTION AND WE HAVE TO SET TO THE INDIVIDUAL SERVICE OBJECTS THOSE
//FOR EXAMPLE IF WE WERE USING USERS AND GROUPS CODE WE NEED TO SET THAT TOKEN TO THE MEMEBR SERVICE
//LIKEWISE FOR WORKFLOW
//msOTAuth.AuthenticationToken = token;
dmOTAuth.AuthenticationToken = token;
Console.WriteLine("Cookie for Admin user--" + token);
DocumentManagement.Node enterprise = dc.GetRootNode( dmOTAuth, "EnterpriseWS");
DocumentManagement.Node folder = dc.CreateFolder( dmOTAuth, enterprise.ID, "TEST" + dmOTAuth.AuthenticationToken.ToString(), null, null);
//In lapi it was always a Method with a session,and any aother parms for it
//that is the same thing that we pass dmOTAuth although webservices do return session tokens to us ?
Console.WriteLine(folder.Name + "was created by " + folder.CreatedBy);
//NOW THESE ARE SIMPLE DOCUMENT MANAGEMENT CALLS
//the user wants to add a document and assign categories to it for this i have created a category called 1 test
//its dataid in my system is 559729 it has two keys Name and Job so for livelink code it is akin to saying
// 559279.1.2 and 559279.1.3 defid that number its version
//ahaboub please see if you understand this
int myCategoryID = 559279;
//we need to ask the sytem for the category definition or you can get it from the node as well if you were adding
//to afolder that had a category attched to it.In this case you are getting the values of the category from a known node
DocumentManagement.AttributeGroup[] attributegroups = new DocumentManagement.AttributeGroup[1];
DocumentManagement.DataValue[] datavalues = new DocumentManagement.DataValue[2];
DocumentManagement.AttributeGroup attributegroup = new DocumentManagement.AttributeGroup();
attributegroup = dc.GetCategoryTemplate(dmOTAuth, 559279);
//once we get the categorytemplate we should put the values that need to go in
//we have two fields in our category called NAME JOB both are manadatory
/*SETTERS FOR INDIVIDUAL VALUES OF THE CATEGORY*/
DocumentManagement.StringValue Name = new AddDocWithCategory.DocumentManagement.StringValue();
Name.Values = new string[1];
Name.Values[0] = "appu";
Name.Key = "559279.1.2"; //VERY VERY BAD PARSING HARD CODING AT ITS BEST
Name.Description = "my name";
DocumentManagement.StringValue Job = new AddDocWithCategory.DocumentManagement.StringValue();
Job.Values = new string[1];
Job.Values[0] = "myjob";
Job.Key = "559279.1.3"; //VERY VERY BAD PARSING HARD CODING AT ITS BEST
Job.Description = "my job";
//you go on adding the contorted data structure here
attributegroup.Values[0] = Name;
attributegroup.Values[1] = Job;
/*SETTERS FOR ATTRIBUTEGROUPS OF THE CATEGORY*/
md.AttributeGroups = new AddDocWithCategory.DocumentManagement.AttributeGroup[1];
md.AttributeGroups[0] = attributegroup;
/*add a file to the folder we created above*/
string filePath = "C:/temp/SAP.pdf";
int newdocid = CreateDocumentInAttachmentID(dc, dmOTAuth, folder.ID, filePath,md);
Console.WriteLine("A Document was uploaded with cats/atts its ID is " + newdocid);
//AHABOUB PLEASE NOTE THAT ONCE A NODE EXISTS YOU JUST HAVE TO FIND IT AND
//DO THE SAME THING WITH A UPDATE NODE
int EXISTINGDOCUMENT_IN_MYLIVELINK = 555096;
DocumentManagement.Node EXISTINGDOCUMENT_IN_MYLIVELINK_NODE = dc.GetNode(dmOTAuth, EXISTINGDOCUMENT_IN_MYLIVELINK);
EXISTINGDOCUMENT_IN_MYLIVELINK_NODE.Metadata = md;
dc.UpdateNode(dmOTAuth, EXISTINGDOCUMENT_IN_MYLIVELINK_NODE);
//VERY VERY IMPORTANT
//IF THE DOCUMENT IN QUESTION HAS ANOTHER CATEGORY ATTACHED THE ABOVE CALL WILL WIPE IT OUT
//SO REALLY YOU HAVE TO ASK THE NODE IF YOU HAVE A CATEGORY AND IF SO ADD THIS NEW METADATA PIECE
Console.ReadLine();
}
else
throw new Exception("Problem obtaining a valid authentication token.");
authClient.Close();
}
catch (Exception e)
{
Console.WriteLine("Error: " + e.Message);
Console.WriteLine(e.StackTrace);
Console.ReadLine();
authClient.Close();
dc.Close();
ms.Close(); //we do not use this in this code
ws.Close();//we do not use this in this code
return;
}//catch ends
}//main ends
static int CreateDocumentInAttachmentID(DocumentManagement.DocumentManagementClient dc, DocumentManagement.OTAuthentication dmOTAuth, int attachmentID, string filePath, DocumentManagement.Metadata md)
{
// DocumentManagement.Metadata md = new DocumentManagement.Metadata();
DocumentManagement.Attachment attach = new DocumentManagement.Attachment();
// Additional objects needed for the upload...
FileInfo fileInfo = new System.IO.FileInfo(filePath);
byte[] contents = File.ReadAllBytes(filePath);
attach.FileName = Path.GetFileName(filePath);
attach.Contents = contents;
attach.FileSize = contents.Length;
attach.CreatedDate = fileInfo.CreationTime;
attach.ModifiedDate = fileInfo.LastWriteTime;
AddDocWithCategory.DocumentManagement.Node myattdoc = dc.CreateDocument(dmOTAuth, attachmentID, "Added document To Attachment", "No Comments", false, md, attach);
return myattdoc.ID;
}
}//class ends
}//namespace ends