Crap, created a application page that reads Active Directory on a Intranet.
But the infrastructure department has deployed it on a sharepoint on the Extranet domain.
Result, could'nt query the additional information in the Active Directory of the users on the intranet.
Somebody told me to use impersonation, but have no experience with this. If someone can help me...
don't hesitate...
If I found a solution, I will keep you informed...
dinsdag 27 december 2011
Active Directory from extranet to intranet domain... Impersonation
donderdag 15 december 2011
Access Active Directory in Sharepoint Application Page
Had to create a redirection page this week that forwarded some Active Directory information
to an external Site for automatic loggon. When deploying my solution to the Sharepoint Server
my code didn't worked for normal users. Found the solution that my testing user
had Farm Admin privileges, for accessing the Active Directory normal users
had'nt enougth rights to excecute the AD call.
Solution found on msdn was to elevate the privileges for specific part of code
that needs that kind of rights.
SPSecurity.RunWithElevatedPrivileges(delegate() { // YOUR CODE THAT NEEDS ELEVATED PRIVILEGES });
dinsdag 15 november 2011
How to update a Hyperlink column
Today I had a little problem for updating a Hyperlink Column by using the List.asmx web service.
I wanted to insert a New item with a Hyperlink Column but not only by giving the URL.
So I searched how to add the description to the Column.
Quickly found that you can use a comma to indicate the URL in the first part
and the description in the second part.
But as you know Sharepoint you must follow certain rules that where not
descripted in the SharePoint Documentation.
So if you need to do the same, keep in mind next rules...
For updating or inserting a Hyperlink value in a Sharepoint list using the List.asmx web services,
make sure to follow these guidelines:
- Notice that URL needs to include “http://” e.g. http://www.google.com/
- If you want to specify a description,
make sure to include a space between the comma (,) and the description.
So our URL field value needs to have ,,
e.g. http://www.google.com/, Google.
batch example:
<Batch OnError=\”Continue\”> <Method ID=\”1\” Cmd=\”New\”> <Field Name=\”URL\”>http://www.google.com, Google</Field> </Method> </Batch>
Labels:
.net,
SharePoint,
SharePoint WebServices,
Web Services
vrijdag 11 november 2011
Building CAML Query, useful site
Building CAML Query
Found this useful site details about building CAML query.
Useful tool for building a CAML query:
- U2U CAML Query Builder
Enjoy it...
How to format decimal in SharePoint Dataview
To translate numbers in SharePoint Dataview, SharePoint Designer generates
following code:
<xsl:value-of select="format-number(@YourField, "$#,##0.00;-$#,##0.00")"/>
Examples:
YourField Result
12345 12,345.00
1234.5 1,234.50
0.0 0.00
If YourField contains a "," you need to use the decimal-format functionality
which will get you something like this:
Outside the xsl:template block:
<xsl:decimal-format name="European" decimal-separator=',' grouping-separator='.' />
To display the field:
<xsl:value-of select='format-number(translate(@YourField,",","."), "#.##0,00", "European")'/>
Examples:
YourField Result
12345 12.345,00
1234.5 1.234,50
0.0 0,00
Labels:
Dataview,
SharePoint,
SharePoint Designer,
xsl
woensdag 9 november 2011
How to Add a Windows SharePoint Web Service Reference
You can add a Web reference to each SharePoint Web service
through your Visual Studio .NET IDE. In your Solution Explorer,
right-click on your project and select "Add Web Reference"
from your popup menu.
The table below shows the URLs to use for each Web service provided by WSS.
Enter the URL to the Web service and click the Go button.
This will show you a summary of all available Web methods in the dialog box.
Next, enter the name of the Web reference and then click Add Reference.
WSS Web Services | Web Reference |
Administration Service | http://[server-url:port-number]/_vti_adm/admin.asmx |
Alerts Service | http://[server-url]/_vti_bin/alerts.asmx |
Document Workspace Service | http://[server-url]/_vti_bin/dws.asmx |
Forms Service | http://[server-url]/_vti_bin/forms.asmx |
Imaging Service | http://[server-url]/_vti_bin/imaging.asmx |
List Data Retrieval Service | http://[server-url]/_vti_bin/dspsts.asmx |
Lists Service | http://[server-url]/_vti_bin/lists.asmx |
Meetings Service | http://[server-url]/_vti_bin/meetings.asmx |
Permissions Service | http://[server-url]/_vti_bin/permissions.asmx |
Site Data Service | http://[server-url]/_vti_bin/sitedata.asmx |
Site Service | http://[server-url]/_vti_bin/sites.asmx |
Users and Groups Service | http://[server-url]/_vti_bin/usergroup.asmx |
Versions Service | http://[server-url]/_vti_bin/versions.asmx |
Views Service | http://[server-url]/_vti_bin/views.asmx |
Web Part Pages Service | http://[server-url]/_vti_bin/webpartpages.asmx |
Webs Service | http://[server-url]/_vti_bin/webs.asmx |
Labels:
.net,
C#,
SharePoint,
SharePoint WebServices,
Visual Studio,
Web Services
Error while creating a new page in SP 2007.
Are you getting the below error while creating a new page in SP 2007 while using publishing
or collaboration portal template?
List does not exist The page you selected contains a list that does not exist. It may have been deleted by another user. at Microsoft.SharePoint.Library.SPRequestInternalClass.GetListsWithCallback(String bstrUrl, Guid foreignWebId, String bstrListInternalName, Int32 dwBaseType, Int32 dwBaseTypeAlt, Int32 dwServerTemplate, UInt32 dwGetListFlags, UInt32 dwListFilterFlags, Boolean bPrefetchMetaData, Boolean bSecurityTrimmed, Boolean bGetSecurityData, ISP2DSafeArrayWriter p2DWriter, Int32& plRecycleBinCount) at Microsoft.SharePoint.Library.SPRequest.GetListsWithCallback(String bstrUrl, Guid foreignWebId, String bstrListInternalName, Int32 dwBaseType, Int32 dwBaseTypeAlt, Int32 dwServerTemplate, UInt32 dwGetListFlags, UInt...
Resolution
Go to Site Settings
- Modify All Site Settings
- Master pages and page layouts
- Add the usergroup who may create sites to the list with Read Restricted Access rights
zaterdag 5 november 2011
Get ListItems using SharePoint Services
Get ListItems with there columns of a specific SharePoint List
using the SharePoint Webservice Lists.asmx .
private XmlNode GetSiteListItems(string sSiteUrl, string sSiteList) { WS_Lists.Lists list = new WS_Lists.Lists(); list.Url = sSiteUrl + "/_vti_bin/lists.asmx"; if (bDefaultLogon) list.Credentials = System.Net.CredentialCache.DefaultCredentials; else { list.PreAuthenticate = true; list.Credentials = new System.Net.NetworkCredential(sTechnicalUser, sTechnicalPw, sDomain); } Console.WriteLine(sSpaces + "Start GetSiteListItems " + sSiteList + " " + sSiteList + "..."); string rowLimit = "99999"; XmlDocument xmlDoc = new System.Xml.XmlDocument(); XmlNode listQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", ""); XmlNode listViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", ""); listViewFields.InnerXml = "<FieldRef Name=\"Title\">" + "<FieldRef Name=\"INTERNAL_FIELDNAME1\"></FieldRef>" + "<FieldRef Name=\"INTERNAL_FIELDNAME2\"></FieldRef>" + "<FieldRef Name=\"INTERNAL_FIELDNAME3\"></FieldRef>" + "<FieldRef Name=\"INTERNAL_FIELDNAME4\"></FieldRef>" + "<FieldRef Name=\"INTERNAL_FIELDNAME5\"></FieldRef>" + "<FieldRef Name=\"INTERNAL_FIELDNAME6\"></FieldRef>" ; XmlNode listQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", ""); XmlNode ndListItems = null; try { ndListItems = list.GetListItems(sSiteList, null, listQuery, listViewFields, rowLimit, listQueryOptions, null); } catch (Exception e) { Console.WriteLine(sSpaces + "Error GetSiteListItems {0}", e.Message); } finally { list.Dispose(); Console.WriteLine(sSpaces + "End GetSiteListItems " + sSiteList + " " + sSiteList); } return ndListItems; }
Labels:
C#,
SharePoint,
SharePoint WebServices,
Web Services
Apply a SiteCollection ContentType on a List of a Site or SubSite
Apply a SiteCollection ContentType on a List using the SharePoint Webservice Lists.asmx .
private Boolean ApplyContentTypeOnList(string myUrl, string myList, string myContentTypeId) { Boolean retCode = true; SetStatus("Initialize webservice..."); WS_Lists.Lists lists = new WS_Lists.Lists(); if (chk_DefaultLoggin.Checked) lists.Credentials = System.Net.CredentialCache.DefaultCredentials; else { lists.PreAuthenticate = true; lists.Credentials = new System.Net.NetworkCredential(txt_UserID.Text, txt_PassWord.Text, txt_domain.Text); } lists.Url = myUrl + @"/_vti_bin/lists.asmx"; try { this.SetStatus("Activate contenttypeID " + myContentTypeId +" on list " + myList); if (TMSI_Trace_On.Checked) this.traceThis("Apply contentType to list..."); XmlNode myNode = lists.ApplyContentTypeToList(myUrl, myContentTypeId, myList); if (myNode.OuterXml == "") { // get ListId for URLLINK XmlNode listID = lists.GetList(myList); retCode = true; } else { retCode = false; } } catch (Exception exception1) { MessageBox.Show(exception1.Message, "Error on applying contenttype on list", MessageBoxButtons.OK); this.SetStatus("Error on applying contenttype on list"); retCode = false; } finally { lists.Dispose(); } return retCode; }
Labels:
C#,
SharePoint,
SharePoint WebServices,
Web Services
Get ContentTypes of a List
Get available ContentTypes on a List using the SharePoint Webservice Lists.asmx .
private void GetListsContentTypes(string myurl, string mylist, ArrayList myAlist) { SetStatus("Initialize webservice..."); myAlist.Clear(); WS_Lists.Lists lists = new WS_Lists.Lists(); if (chk_DefaultLoggin.Checked) lists.Credentials = System.Net.CredentialCache.DefaultCredentials; else { lists.PreAuthenticate = true; lists.Credentials = new System.Net.NetworkCredential(txt_UserID.Text, txt_PassWord.Text, txt_domain.Text); } lists.Url = myurl + @"/_vti_bin/lists.asmx"; try { this.SetStatus("getting contenttypes for list " + mylist); XmlNode myNode = lists.GetListContentTypes(mylist, "0x01"); XmlNodeList nodes = myNode.SelectNodes("*"); foreach (XmlNode node in nodes) { myAlist.Add(node.Attributes["Name"].Value); } } catch (Exception exception1) { MessageBox.Show(exception1.Message, "Error loading list info", MessageBoxButtons.OK); this.SetStatus("Error loading list info"); } finally { lists.Dispose(); } }
Labels:
C#,
SharePoint,
SharePoint WebServices,
Web Services
Clone a View to you new List based on your Template ListView
Clone a view of a template list to your new list
using the SharePoint Webservice Views.asmx .
private void CloneViewXML(string mytemplateUrl ,string myurl, string mylist, string myview ) { SetStatus("Initialize webservice..."); SetStatus("Calling webservice..."); Boolean retcode = true; WS.Views views = new WS.Views(); if (chk_DefaultLoggin.Checked) views.Credentials = System.Net.CredentialCache.DefaultCredentials; else { views.PreAuthenticate = true; views.Credentials = new System.Net.NetworkCredential(txt_UserID.Text, txt_PassWord.Text, txt_domain.Text); } views.Url = mytemplateUrl + @"/_vti_bin/Views.asmx"; try { this.SetStatus("getting viewxml for view " + myview + " on list " + mylist ); XmlNode myListNode = views.GetViewCollection(mylist); XmlNodeList lnodes = myListNode.SelectNodes("*"); String viewGuid = ""; XmlNode vnQuery = null; XmlNode vnFields = null; XmlNode vnRowLimit = null; foreach (XmlNode lnode in lnodes) { // ID of the View if (lnode.Attributes["DisplayName"].Value == myview) viewGuid = lnode.Attributes["Name"].Value; } /// if no guid found... exit if (viewGuid != "") { XmlNode viewxml = views.GetView(mylist, viewGuid); // internal listname en view guid String sViewType = viewxml.Attributes["Type"].Value; XmlNodeList nodes = viewxml.SelectNodes("*"); foreach (XmlNode node in nodes) { if (node.Name == "Query") vnQuery = node; if (node.Name == "ViewFields") vnFields = node; if (node.Name == "RowLimit") vnRowLimit = node; } if (vnQuery != null && vnFields != null && vnRowLimit != null) { if (TMSI_Trace_On.Checked) this.traceThis("Creating view..."); // call function to create the new view... retcode = CreateView(myurl, mylist, myview, sViewType, vnQuery, vnFields, vnRowLimit, false); if (!retcode) { this.SetStatus("creation of view failed...."); } else { this.SetStatus("view created"); } } } else { this.SetStatus("Error on finding template view guid"); retcode = false; } this.SetStatus(""); } catch (Exception exception1) { MessageBox.Show(exception1.Message, "Error loading view info", MessageBoxButtons.OK); this.SetStatus("Error loading view info"); retcode = false; } finally { views.Dispose(); } } private Boolean CreateView(String myUrl, String myList, String myView, String myViewType, XmlNode myQuery, XmlNode myFields, XmlNode myRowLimit, Boolean myDefaultView) { Boolean retcode = true; SetStatus("Initialize webservice..."); WS_Views.Views views = new WS_Views.Views(); if (chk_DefaultLoggin.Checked) views.Credentials = System.Net.CredentialCache.DefaultCredentials; else { views.PreAuthenticate = true; views.Credentials = new System.Net.NetworkCredential(txt_UserID.Text, txt_PassWord.Text, txt_domain.Text); } views.Url = myUrl + @"/_vti_bin/Views.asmx"; try { XmlNode retnode = views.AddView(myList, myView, myFields, myQuery, myRowLimit, myViewType, myDefaultView); SetStatus("View " + myUrl + myList + myView + "created.."); } catch (Exception exeption1) { this.SetStatus("Error on Create View" + exeption1.Message); retcode = false; } finally { views.Dispose(); } return retcode; }
Labels:
C#,
SharePoint,
SharePoint WebServices,
Web Services
Get all Views defined on a List
In this function fill's in a ArrayList with the list of Views defined on a Site
using the SharePoint Webservice Views.asmx .
private void GetNewListsViews(string myurl, string mylist, ArrayList myAlist) { SetStatus("Initialize webservice..."); myAlist.Clear(); WS_Views.Views views = new WS_Views.Views(); if (chk_DefaultLoggin.Checked) views.Credentials = System.Net.CredentialCache.DefaultCredentials; else { views.PreAuthenticate = true; views.Credentials = new System.Net.NetworkCredential(txt_UserID.Text, txt_PassWord.Text, txt_domain.Text); } views.Url = myurl + @"/_vti_bin/Views.asmx"; try { this.SetStatus("getting views for list " + mylist); XmlNode myNode = views.GetViewCollection(mylist); XmlNodeList nodes = myNode.SelectNodes("*"); foreach (XmlNode node in nodes) { if (node.Attributes["DisplayName"].Value != "") myAlist.Add(node.Attributes["DisplayName"].Value); } } catch (Exception exception1) { MessageBox.Show(exception1.Message, "Error loading list info", MessageBoxButtons.OK); this.SetStatus("Error loading list info"); } finally { views.Dispose(); } }
Labels:
C#,
SharePoint,
SharePoint WebServices,
Web Services
Get Permissions info of a List or a Site
In this function fill's in a ArrayList with the some permission properties of
users or usergroups of a Site or a List using the SharePoint Webservice Lists.asmx .
private void GetSPPermissions(string myurl, string mylist, string stype, ArrayList myAlist) { SetStatus("Initialize webservice..."); myAlist.Clear(); WS_Permissions.Permissions permissions = new WS_Permissions.Permissions(); if (chk_DefaultLoggin.Checked) permissions.Credentials = System.Net.CredentialCache.DefaultCredentials; else { permissions.PreAuthenticate = true; permissions.Credentials = new System.Net.NetworkCredential(txt_UserID.Text, txt_PassWord.Text, txt_domain.Text); } permissions.Url = myurl + @"/_vti_bin/permissions.asmx"; try { // stype can contain Web or List depending if mylist contains a listname or a sitename XmlNode myNode = permissions.GetPermissionCollection(mylist, stype); XmlNodeList pnodes = myNode.SelectNodes("*"); foreach (XmlNode pnode in pnodes) { foreach (XmlNode node in pnode) { ArrayList userList = new ArrayList(); string mId = node.Attributes["MemberID"].Value; string mMask = node.Attributes["Mask"].Value; string mIsUser = node.Attributes["MemberIsUser"].Value; string mRoleName = ""; string mUserLogin = ""; if (mIsUser.ToLower().Equals("true")) { mUserLogin = node.Attributes["UserLogin"].Value; } else { mRoleName = node.Attributes["GroupName"].Value; } string mGlobal = node.Attributes["MemberGlobal"].Value; string mName = ""; if (mIsUser.Equals("False")) mName = mRoleName; else mName = mUserLogin; userList.Add(mName); userList.Add(mIsUser); userList.Add(mRoleName); userList.Add(mGlobal); myAlist.Add(userList); } } } catch (Exception exception1) { MessageBox.Show(exception1.Message, "Error loading Permissions info", MessageBoxButtons.OK); this.SetStatus("Error loading Permissions info"); } finally { permissions.Dispose(); } }
Labels:
C#,
SharePoint,
SharePoint WebServices,
Web Services
Get available Lists on a Site
In this function fill's in an ArrayList with all available Lists on a Site using the SharePoint
Webservice Lists.asmx .
Little remark, a document library is also a list and will also be returned by the webservice.
private void GetLists(string myurl, ArrayList myAList) { SetStatus("Initialize webservice..."); myAList.Clear(); WS_Lists.Lists lists = new WS_Lists.Lists(); if (chk_DefaultLoggin.Checked) lists.Credentials = System.Net.CredentialCache.DefaultCredentials; else { lists.PreAuthenticate = true; lists.Credentials = new System.Net.NetworkCredential(txt_UserID.Text, txt_PassWord.Text, txt_domain.Text); } lists.Url = myurl + @"/_vti_bin/lists.asmx"; try { this.SetStatus("Getting lists for site " + myurl); XmlNode myNode = lists.GetListCollection(); XmlNodeList nodes = myNode.SelectNodes("*"); foreach (XmlNode node in nodes) { myAList.Add(node.Attributes["Title"].Value); } } catch (Exception exception1) { MessageBox.Show(exception1.Message, "Error loading list info", MessageBoxButtons.OK); this.SetStatus("Error loading list info"); } finally { lists.Dispose(); } }
Labels:
C#,
SharePoint,
SharePoint WebServices,
Web Services
Get all Sites and SubSites of a SiteCollection
In this function you receive a ArrayList containing all Sites/SubSites of a SiteCollection using
the SharePoint Webservice Webs.asmx .
private ArrayList GetSites(string siteurl) { SetStatus("Initialize webservice..."); ArrayList myList = null; // reading al the sites and subsites via webservice WS_Webs.Webs webs = new WS_Webs.Webs(); if (chk_DefaultLoggin.Checked) webs.Credentials = System.Net.CredentialCache.DefaultCredentials; else { webs.PreAuthenticate = true; webs.Credentials = new System.Net.NetworkCredential(txt_UserID.Text, txt_PassWord.Text, txt_domain.Text); } webs.Url = siteurl + @"/_vti_bin/webs.asmx"; try { XmlNode myNode = webs.GetAllSubWebCollection(); XmlNodeList nodes = myNode.SelectNodes("*"); foreach (XmlNode node in nodes) { // only add sites that starts with the given site url if ( node.Attributes["Url"].Value.StartsWith(siteurl)) myList.Add(node.Attributes["Url"].Value); } } catch (Exception exception1) { MessageBox.Show(exception1.Message, "Error loading siteinfo", MessageBoxButtons.OK); this.SetStatus("Error loading site info"); } finally { webs.Dispose(); } }
Labels:
C#,
SharePoint,
SharePoint WebServices,
Web Services
Get Site description
In this function you receive the description of a Site using the SharePoint
Webservice Webs.asmx .
private string GetSiteDescription(string siteurl) { SetStatus("Initialize webservice..."); string siteDesc = ""; // reading al the sites and subsites via webservice WS_Webs.Webs webs = new WS_Webs.Webs(); if (chk_DefaultLoggin.Checked) webs.Credentials = System.Net.CredentialCache.DefaultCredentials; else { webs.PreAuthenticate = true; webs.Credentials = new System.Net.NetworkCredential(txt_UserID.Text, txt_PassWord.Text, txt_domain.Text); } webs.Url = siteurl + @"/_vti_bin/webs.asmx"; try { XmlNode myNode = webs.GetWeb(siteurl); if (myNode != null) { siteDesc = myNode.Attributes["Description"].Value; } } catch (Exception exception1) { MessageBox.Show(exception1.Message, "Error loading SiteName", MessageBoxButtons.OK); this.SetStatus("Error loading site Name info"); } finally { webs.Dispose(); } return siteDesc; }
Labels:
C#,
SharePoint,
SharePoint WebServices,
Web Services
Get the name of a Site
In this function you receive the Name of a Site based on the Site Url, this using the SharePoint
Webservice Webs.asmx
private string GetSiteName(string siteurl) { SetStatus("Initialize webservice..."); string siteName = ""; // reading al the sites and subsites via webservice WS_Webs.Webs webs = new WS_Webs.Webs(); if (chk_DefaultLoggin.Checked) webs.Credentials = System.Net.CredentialCache.DefaultCredentials; else { webs.PreAuthenticate = true; webs.Credentials = new System.Net.NetworkCredential(txt_UserID.Text, txt_PassWord.Text, txt_domain.Text); } webs.Url = siteurl + @"/_vti_bin/webs.asmx"; try { XmlNode myNode = webs.GetWeb(siteurl); if (myNode != null) { // only add sites that starts with the given site url siteName = myNode.Attributes["Title"].Value; } } catch (Exception exception1) { MessageBox.Show(exception1.Message, "Error loading SiteName", MessageBoxButtons.OK); this.SetStatus("Error loading site Name info"); } finally { webs.Dispose(); } return siteName; }
Labels:
C#,
SharePoint,
SharePoint WebServices,
Web Services
How to get the list of users defined in a SharePoint Group
This is an example of how you can receive the users of a SharePoint Group using the SharePoint
Webservice UserGroup.asmx and put the result in a ArrayList.
private void GetUserOfGroup(string myurl,string sUGroup, ArrayList myAlist) { SetStatus("Initialize webservice..."); WS_UserGroup.UserGroup usergroup = new WS_UserGroup.UserGroup(); if (chk_DefaultLoggin.Checked) usergroup.Credentials = System.Net.CredentialCache.DefaultCredentials; else { usergroup.PreAuthenticate = true; usergroup.Credentials = new System.Net.NetworkCredential(txt_UserID.Text, txt_PassWord.Text, txt_domain.Text); } usergroup.Url = myurl + @"/_vti_bin/usergroup.asmx"; try { this.SetStatus("Getting Users for group " + sUGroup); XmlNode myNode = usergroup.GetUserCollectionFromGroup(sUGroup); XmlNodeList unodes = myNode.SelectNodes("*"); foreach (XmlNode pnode in unodes) { foreach (XmlNode node in pnode) { ArrayList mAList = new ArrayList(); string mName = node.Attributes["Name"].Value; string mLoginName = node.Attributes["LoginName"].Value; string mEmail = node.Attributes["Email"].Value; string mSiteAdmin = node.Attributes["IsSiteAdmin"].Value; string mDomainGroup = node.Attributes["IsDomainGroup"].Value; mAList.Add(sUGroup); mAList.Add(mName); mAList.Add(mLoginName); mAList.Add(mEmail); mAList.Add(mSiteAdmin); mAList.Add(mDomainGroup); myAlist.Add(mAList); } } } catch (Exception exception1) { MessageBox.Show(exception1.Message, "Error loading GetUsersOfGroup ", MessageBoxButtons.OK); this.SetStatus("Error loading GetUsersOfGroup "); } finally { usergroup.Dispose(); } this.SetStatus(""); }
Labels:
C#,
SharePoint,
SharePoint WebServices,
Web Services
Abonneren op:
Posts (Atom)