Sharepoint2010 Programmaticaly assign the prefix for the Document ID Service - sharepoint-2010

I'm creating a new site collection where the document ID service should be activated. How can i programmatically set the prefix for the document ID service inside the new site collection?
[EDIT]
This seems to be the solution.
using (SPSite rootSite = new SPSite(URL + "sites/123021")) {
rootSite.Features.Add(new Guid("b50e3104-6812-424f-a011-cc90e6327318"));
using (SPWeb web = rootSite.OpenWeb(String.Empty, true)){
web.Properties["docid_settings_ui"] = "<?xml version=\"1.0\" encoding=\"utf-16\"?><DocIdUiSettings xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Prefix>88888</Prefix><AssignmentEnabled>true</AssignmentEnabled></DocIdUiSettings>";
web.AllProperties["docid_settings_ui"] = "<?xml version=\"1.0\" encoding=\"utf-16\"?><DocIdUiSettings xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Prefix>88888</Prefix><AssignmentEnabled>true</AssignmentEnabled></DocIdUiSettings>";
web.Update();
}
}
Thanks
Marco

You can change the prefix used by the document id service by setting the docid_msft_hier_siteprefix property of the RootWeb of the site collection (change it in both the Properties and AllProperties property bags.
Toby

I verified the "Answer" for SharePoint 2013, it does set the prefix in the Document ID settings page. But the timer jobs for Document ID service wont apply the new prefix. you should try this
// Set document id service prefix
DocumentId.SetDefaultProvider(rootSite);
DocumentId.EnableAssignment(rootSite, "MYPREFIX", true, true, true, false);
for more details information please see my blog post on this issue.
http://blogs.perficient.com/multi-shoring/blog/2015/01/13/set-document-id-prefix-programmatically-in-sharepoint-2013/

Related

Iron Web Scraper - Login

I've read the tutorials to log into a website prior to scraping it, but it just ain't workin'. I constructed a HttpIdentity object, added it to the Identities collection, and processed the request, but the page returned to scrape was still the login page. There isn't a lot about this on their website and documentation. Here's my code for that:
var identity = new HttpIdentity
{
UseCookies = true,
NetworkUsername = _username,
NetworkPassword = _password
};
Identities.Add(identity);
Request(_uri, Parse, identity);
In the Parse method I get a Response object returned with a Status Code of 200, and the "WasSuccessful" property of Response is "true". It seems that I should be redirected to the page I was trying to access, but I'm just getting the login html.
Is there something I'm missing?
I wasn't able to find a solution using the Iron Web Scraper, but I was able to do it with ScrapySharp, which is a free utility, so it worked out. ScrapySharp is able to mimic a browser to a degree, so navigation and submitting forms is pretty easy.
var browser = new ScrapingBrowser();
var homepage = browser.NavigateToPage(_Uri); // login Uri
var form = homepage.FindForm("login"); // get form by name
form.Method = HttpVerb.Post;
form["username"] = "my_username"; // get form fields by id
form["password"] = "my_password";
var resultPage = form.Submit(); // login
var loggedInPage = browser.NavigateToPage(new Uri("https://path.to.target.page"));
And that's it. I'm not sure what the problem was with Iron Web Scraper. Maybe some ajax on the login page. In any case, this code is working for me now.

OCR at OneNote using VBA [duplicate]

I need to do the simple Program whcih need to extract text from image using Onenote Interop? Could any one suggest me the appropriate document for my concept please?
Text recognized by OneNote's OCR is stored in the one:OCRText element in the XML file structure in OneNote. e.g.
<one:Page ...>
...
<one:Image ...>
...
<one:OCRData lang="en-US">
<one:OCRText><![CDATA[This is some sampletext]]></one:OCRText>
</one:OCRData>
</one:Image>
</one:Page>
You can see this XML using a program called OMSPY (it shows you the XML behind OneNote pages) - http://blogs.msdn.com/b/johnguin/archive/2011/07/28/onenote-spy-omspy-for-onenote-2010.aspx
To extract the text you would use the OneNote COM interop (as you pointed out). e.g.
//Instantialize OneNote
ApplicationClass onApp = new ApplicationClass();
//Get the XMl from the selected page
string xml = "";
onApp.GetPageContent("put the page id here", out xml);
//Put it into an XML document (from System.XML.Linq)
XDocument xDoc = XDocument.Parse(xml);
//OneNote's Namespace - for OneNote 2010
XNamespace one = "http://schemas.microsoft.com/office/onenote/2010/onenote";
//Get all the OCRText from the page
string[] OCRText = xDoc.Descendants(one + "OCRText").Select(x => x.Value).ToArray();
See the "Application Interface" docs on MSDN for more info - http://msdn.microsoft.com/en-us/library/gg649853.aspx

Retrieve the name of a document which saved in a SharePoint library using Client Object Model

foreach (SPListItem item in listitems)
{
AttachmentControlTemplate atch_templt = new AttachmentControlTemplate(countr);
atch_templt.lnk_btn.Text = item.File.Name;
atch_templt.lnk_btn.OnClientClick = "window.open('" + site_url + "/" + item.File.Url + "')";
}
Above sever side code shows the way of retrieving the name of a document which saved in a SharePoint document library by using "item.File.Name",i have done this completely, but how do i do same thing by using Client Object Model. What should i use instead of "item.File.Name".
Would anyone help me to sort this out ??
Any help is greatly appreciated.
finally i have found the way to get the Url of a saved document. i am sharing it with others. i have retrieved the file name and concatenated with the Url of the document library.
var fileUrl = "Document library Url" + "File Name";
By using above fileUrl, the document can be opened.

How to get the full URL from an SPWEB

I have a VB console application.
I would like to get the absolute URL of the page.
Here is my current code:
Using siteCollectSPSite As New SPSite("http://mySite")
Dim blogPostSpList As SPList
'Get only the subsite of <locale/blogs>
Using blogSiteSPWeb As SPWeb = siteCollectSPSite.OpenWeb("/blogs")
For Each subsite As SPWeb In blogSiteSPWeb.Webs
Console.WriteLine("Subsite title: " & subsite.Url)
'......
Next
Right now, what I get is: http://mySite/blogs/myblog1
What I want to get is the full URL: http://mySite/blogs/myblog1/default.aspx
How can I get the "default.aspx"?
WelcomePage is the property of SPFolder type so to get the full url , you have to use :
subsite.Url + "/" + subsite.RootFolder.WelcomePage;
SPFolder.WelcomePage should have worked. If it didn't you need to set the "vti_welcomepage" in the properties of the Folder list item. This is what MS does under the hood.
if (this.m_strRedirectUrl == null)
{
string text = (string)this.Properties["vti_welcomepage"];
if (text == null)
{
text = string.Empty;
}
this.m_strRedirectUrl = text;
}
return this.m_strRedirectUrl;
Ok so your problem is that SPWeb doesnt actually have a 'page' as such. Default.aspx is simply one page inside the SPWeb container.
You can modify/read the default page using publishingWeb if you have the publishing feature enabled otherwise try this:
http://curia.me/post/2011/05/20/SharePoint-how-change-the-default-page-of-a-SPWeb.aspx

How might I create a SharePoint 2010 content query web part programatically?

How might I create a SharePoint 2010 content query web part programatically and add it to a SharePoint page?
The post Adding/Removing web part in SharePoint website programmatically using C# code contains a detailed description of adding and removing Web Parts.
Here's a snippet taken from the above post adding a Web Part to a page (replace the WebPartToBeAdded pseudoclass with ContentByQueryWebPart):
using (SPSite spSiteTest = new SPSite(“SiteURL”)
{
using (SPWeb spWebTest = spSiteTest.OpenWeb())
{
SPWebPartCollection webparts = spWebTest.GetWebPartCollection("WebPageURL",Storage.Shared);
//create new webpart object
WebPartToBeAdded wpNew = new WebPartToBeAdded();
//set properties of new webpart object
wpNew.ZoneID = "WebPartZoneIDWhereWebPartIsToBeAdded";
wpNew.Title = "Web Part Title";
wpNew.ChromeState = System.Web.UI.WebControls.WebParts.PartChromeState.Normal;
wpNew.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.None;
//add new webpart object to webparts collection
webparts.Add(wpNew);
//update spWeb object
spWebTest.Update();
}
}