How do you move a SharePoint 2010 DocumentSet from one list to another? - api

I've tried many variations.
Send To Library - That creates a Zipped file in the Drop Off Library, then it doesn't route via the rules in Content Organizer
API - I've tried to do an Export, Import, but always receive the same error. This is per this MSDN documentation: http://msdn.microsoft.com/en-us/library/microsoft.office.documentmanagement.documentsets.documentset.create.aspx
Sample snippet:
byte[] exportedFile = set.Export();
DocumentSet.Import(exportedFile, DocSetNameToCreate, targetFolder, dsCt.Id, properties, web.CurrentUser);
Error Received:
DocID: Site prefix not set.

Finally got it to run. This is related to the Document ID Feature. Make sure it is activated in each site. Let is run over night (timer jobs need to run). Then the content organizer will successfully move and unpackage your document sets.

You don't have to activate the document id feature, just ensure that in the property bag of the root web of the destination site collection (where the document set will be imported again) exists a property named "docid_msft_hier_siteprefix" with an value of "" (empty string).
Use this powershell-script:
$site = Get-SPSite http://host/sites/yoursite
$properties = $site.RootWeb.Properties
if ($properties["docid_msft_hier_siteprefix"] -eq $null)
{
$properties["docid_msft_hier_siteprefix"] = ""
$properties.Update()
}
Note that i use the old property bag RootWeb.Properties instead of the new hashtable RootWeb.AllProperties, thats because the class Microsoft.Office.DocumentManagement.Internal.OobProvider still uses that.
So why is it failing when a document set is imported? The function DocumentSet.ImportProperties() catches an ArgumentException while trying to set the document id of the document set list item (so there's no problem if the document id column doesn't exist yet).
But they missed that the function OobProvider.GetSitePrefix() which is called through the function OobProvider.GenerateDocumentId() throws an InvalidOperationException if the property bag doesn't contain the prefix property.

Related

Unable to add custom user property even if it does not exist

I have implemented VSTO plug-in for Outlook 2016 / 2019. I have added one custom property. On production, for one user (this user has tried on different machines as well), whenever we try to add our custom property we get exception.
I am using following code snippet :--
UserProperty securedFlag = mailItem.UserProperties.Find("Custom.Secured", true);
int currentValue = -1;
if (securedFlag == null)
{
try
{
securedFlag = mailItem.UserProperties.Add("Custom.Secured", OlUserPropertyType.olInteger, false, OlFormatInteger.olFormatIntegerPlain);
}
catch(System.Exception ex)
{
DarkAddInEventLog.WriteException(ex, "Secure");
}
}
When we execute above code, it is throwing following exception :--
"A custom field with this name but a different data type already exists. Enter a different name."
I have also tried to search same property in non-custom properties by passing false (in second argument of find API) which also throws exception that this property does not exist. Therefore it seems confirmed that this property does not exist before.
Now I have 2 doubts :--
1- If this property does not exist, then why outlook is throwing this error ?
2- Same plug-in is working with other users but only one user is facing this issue. Is it related to some mailbox configuration ?
The error means a property with the same name has already been used in the same mailbox, it might not even be your property, but since all custom properties use the same GUID (PS_PUBLIC_STRINGS), you can run into this problem with duplicate names.
Your only option is to either use a different name (and make sure it is not generic enough to conflict with other properties created by some other apps - e.g. you can prefix all your properties with a unique prefix, such as "MyCompanyProp.") or avoid using UserProperties collection completely and set your custom properties using PropertyAccessor specifying the full DASL name of the named properties with your own custom GUID.

Variable does not save event.response from network.request -Lua

I am trying to create a Lua program using Sublime and Corona. I want to fetch a webpage, use a pattern to extract certain text from the page, and then save the extracted text into a table. I am using the network.request method provided by Corona
The problem: The extracted text is not saving into the global variable I created. Whenever I try to reference it or print it outside of the function it returns nil. Any ideas why this is happening?
I have attached a screen shot of my event.response output. This is what I want to be saved into my Lua table
Event.response Output
Here is my code:
local restaurants = {}
yelpString = ""
--this method tells the program what to do once the website is retrieved
local function networkListener( event )
if ( event.isError ) then
print( "Network error: ", event.response )
else
yelpString = event.response
--loops through the website to find the pattern that extracts
restaurant names and prints it out
for i in string.gmatch(yelpString, "<span >(.-)<") do
table.insert(restaurants, i)
print(i)
end
end
end
-- retrieves the website
network.request( "https://www.yelp.com/search?
cflt=restaurants&find_loc=Cleveland%2C+OH%2C+US", "GET", networkListener )
This sounds like a scoping problem. From the output you give, it looks like networkListener is being called, and you are successfully adding the text into the restaurants table. Moreover, since you define restaurants as a table, it should be a table when you reference it, not nil. So by deduction, the issue must be that you are trying to access the restaurants table from somewhere where it is not in scope.
If you declare restaurants as "local" in the top level of a file (i.e. not within a function or a block), it will be accessible to the whole file, but it won't be accessible to anything outside the file. So the table.insert(restaurants, i) in your code will work, but if you try to reference restaurants from somewhere outside the file, it will be nil. I'm guessing this is the cause of the problems that you are running into.
For more details on scope, have a look at the Programming in Lua book. The book is for Lua 5.0, but the scoping rules for local variables have not changed in later versions of Lua (as of this writing, the latest is Lua 5.3).

GOS attachments download

Basically I have some attachments listed in the Generic Object Services (GOS) and I need to download all of them to my computer.
I need to know how do download these attachments programatically from my program/report.
I've never actually had to do this myself, but I think this is how it's done:
Get the list of attachments by calling cl_binary_relation=>read_links passing in the ID of the object that the attachments are attached to. The it_relation_options table should be filled with a relation like so:
la_relat-sign = 'I'.
la_relat-option = 'EQ'.
la_relat-low = 'ATTA'. "Attachements
APPEND la_relat TO lt_relat.
This tells read_links to get the related objects classed as attachments.
Once you've successfully got the attachment details, you should be able to loop over the results table and pass each to the SO_OBJECT_READ function module (if that doesn't work try SO_DOCUMENT_READ_API1). This expects a folder id and a document id; in the results of read_links these may be concatenated together into one string (with the object type, e.g. SOFM at the front).
SO_OBJECT_READ will give you the binary content. You can then call SO_OBJECT_DOWNLOAD with (I think) filetype = 'BIN'.
Hope that helps!

Content Organizer Rule Creation Issue

I am using the Content Organizer feature to move documents of a specific content type into a specific folder in a document library in the same site. I created a content organizaer rule with a property setting that uses the property testcolumn. Testcolumn is a site column defined as a lookup to column on a custom List, testlist, and then added to a site content type. The items in this list are displayed in the Value dropdown list and I can select the specific value I want to use for this rule.
The problem is that I can create and save rules provided that there are no more than 19 items in the testlist list. When I have 20 items in the testlist, it looks like the rule was saved by the UI. If I open the rule and go to edit it, the Value for the testcolumn property is (None). If I look at the item in powershell, the Value property is equal to '0' and not the ID of the item I saved in the UI. If I delete a record in the testlist so that the total number of items drops below 20, I can save the rule without issue. I have tried different combinaitions of items in the list in case it was a text issue, but when I have 20 items or more in the list, the rule is not saved.
I have looked at the ULS logs and it states the "Routing Engine: UpdateRule() has successfully updated the rule, rule.Name=TestRule1" when I save the rule.
Thanks for your help.
The answer is partially listed here. Looks like the page renders the control differently if the number of items is 20 or greater. The content organizer rule creation page does not handle this change and does not show any error when saving the information.
I was able to get around this limitation in the UI by adding the rules through code during my feature creation event. A link to creating rules through code is here.

SharePoint SPFile change extension on existing item possible?

I am at my wits end on this one. I have a user interface that creates and edits documents stored in a SharePoint document library. The trick part is I need to allow the user to update the document no problem just use SPFile.SaveBinary() right?
This definitely updates the contents of the file but somehow the old file name and the old extension persist, this is a problem. Deleting and re-adding the list item is not a solution either because the id of the item is being referenced in the url.
My question is how can I update the extension and filename metadata of the SPFile item?
So far all of my attempts using the object library have failed, i've tried updating the fields below none have been successful. It seems like there has to be an easier way to do this.
SPFile file = item.File;
file.Item[SPBuiltInFieldId.FileLeafRef] = resolvedFileName;
file.Item[SPBuiltInFieldId.FileRef] = "/File/" + resolvedFileName;
file.Item[SPBuiltInFieldId.BaseName] = System.IO.Path.GetFileNameWithoutExtension(resolvedFileName);
file.Item["Name"] = System.IO.Path.GetFileNameWithoutExtension(resolvedFileName);
file.SaveBinary(conduitFile);
file.Update();
[EDIT] - Here is my working solution.
SPFile file = item.File;
string resolvedFileName = item.ID.ToString() + "-" + conduitFileName;
item["Title"] = resolvedFileName;
file.SaveBinary(conduitFile);
file.MoveTo(item.ParentList.RootFolder.Url + "/" + resolvedFileName, true);
file.Item["Name"] = resolvedFileName;
file.Update();
After the file is saved to the library, use the MoveTo method and pass the modified file name in the newUrl parameter.
SPFile.MoveTo Method (String)
Quick & Easy: Rename Uploaded File Using SharePoint Object Model Via an Event Receiver
Another way that is simpler than using the MoveTo is to use the BaseName property of the SPListItem. You would set this by running
item["BaseName"] = resolvedFileName; //Whatever you want the new file name to be
item.Update();
This is easier than MoveTo because you don't have to worry about the folder hierarchy and you don't have to worry about the file extension.
For some reason the property is not listed on the MSDN documentation, but it seems to work well without a problem.