Home
TeamSite
Move document between folders.
cheld
Hi,
Can you please point me in the right direction to be able to MOVE a file from one document folder to another in worksite/desksite 8.0. I can add the document to another folder updating its profile and security accordingly, but are unable to remove it from the original folder. I tried to implement the...
foreach (IManAdditionalProperty ap in addProps)
{
DOC.SetAttributeByID(GetAttributeIDFromFolderProfileKey(ap.Name), ap.Value);
}
DOC.Update();
IManDocuments destDox = (IManDocuments)destination.Contents;
DOC = (IManDocument)destDox.AddDocumentReference(DOC);
The above code successfully adds the document to the new folder. How would I remove it from the original folder.
The manual steps to re-create our exact desired functionality in Desksite 8.0 is:
highlight a folder with the document you wish to move
left-click on said document, drag it to the new folder (we can already ADD the document to the new folder...but cannot remove it from the original)
user is prompted whether to update profile and security info (we can already do this)
upon the completion of this process the document has been moved to its new folder (whether the profile and security info is updated is irrelevant) but the document now only exists in the 'new' folder.
I cannot find any code on how to get this done...any and all help is appreciate.
Thanks,
Chris
Find more posts tagged with
Comments
jny
You may want to use the Refile method instead. Like so:
using IManage;
private void Form1_Load(object sender, EventArgs e)
{
//Login
IManDMS dms = new ManDMSClass();
IManSession sess = dms.Sessions.Add("NTDEVSUPPORT");
sess.TrustedLogin();
// Get destination database
IManDatabase db = sess.Databases.ItemByName("DSS1");
// Get destination folder by search method.
ManStrings list = new ManStringsClass();
list.Add(db.Name);
IManFolderSearchParameters parms = dms.CreateFolderSearchParameters();
parms.Add(imFolderAttributeID.imFolderName, "TestRuleFolder");
IManDocumentFolder fldr = (IManDocumentFolder)sess.WorkArea.SearchFolders(list, parms).ItemByIndex(1);
// Get the document-to-refile
IManDocument doc = db.GetDocument(802, 1);
// Add document to the destination folder
IManDocuments fldrDox = (IManDocuments) fldr.Contents;
doc = (IManDocument)fldrDox.AddDocumentReference(doc);
// Create a blank profile
IManProfile prof = sess.PreferredDatabase.CreateBlankProfile();
// Copy folder additional properties to the blank profile
foreach (IManAdditionalProperty ap in fldr.AdditionalProperties)
{
prof.SetAttributeByID (GetAttributeIDFromFolderProfileKey(ap.Name), ap.Value);
}
// Refile document
IManProfileUpdateResult result = doc.Refile(prof, fldr.Security);
}
///
/// This method returns the attributeID that is stored in the AdditionalProperty of a folder.
///
/// The string value that represents the attributeID,
/// plus its prefix, belonging to the folder document profile
/// The numeric value for the specified attributeID enum
public static imProfileAttributeID GetAttributeIDFromFolderProfileKey(string key)
{
const string FOLDER_PROFILE_PREFIX = "iMan___";
const imProfileAttributeID ATTRIBUTE_ID_NULL = (imProfileAttributeID)(-1);
string originalAttributeIDValue = key.Substring(FOLDER_PROFILE_PREFIX.Length);
if (originalAttributeIDValue.Length > 0)
{
double attr;
if (double.TryParse(originalAttributeIDValue, System.Globalization.NumberStyles.Integer, null, out attr))
{
return (imProfileAttributeID)(int)attr;
}
}
return ATTRIBUTE_ID_NULL;
}
egauthier
this post deserves a sticky and to be in the documentation of the API !!!
I spent almost a day looking for what the sample code is doing.
By the way I don't understand why there is no Profile object available on a Folder...
anyway great code sample thanks
guido1
Document folders don't have a Profile simply because no profile information is stored against them in the database. They use additional property settings to persist information about profile-related data such as Custom1, Custom2 etc.
egauthier
Thanks for answering me but I still don't get the logic.
if these are additionnal properties, where are they stored ?
it can't be local since the properties are here whatever the environment we're using for displaying the folder's profile information, worksite web, filesite, desksite... so this information must exist somewhere in the database even if it's not sotred directly like for workspaces, thus it's possible to build a profile object for a documentFolder (proof is the above code), then why isn't it present in the API ?
guido1
Yes, the values are persisted in the database. From memory they're stored in the PROJECT_NVPS table.
In that table each row represents a name/value pairing for each folder's Additional Property value.
From an API point of view, check the AdditionalProperties collection of the IManFolder
egauthier
Thanks for your inputs Guido