When the designer (or anyone else) tried to modify an aspx page or master page of one of our public sites, he could open aspx pages, but when he tried to save those or when he tried to open a master page, he got the following error:
"The server could not complete your request. Contact your Internet service provider or Web server administrator to make sure that the server has the FrontPage Server Extensions or SharePoint Services installed."
Clicking on "Details" gave a blank error. A lot of googling suggested recycling the application pool (didn't work) or extending the web application (that didn't apply to our situation, since that was when you were using FBA in stead of Windows authentication and we were using Windows authentication). The last option made me take a look at the security settings though, and that's where I found a solution that worked for me. It turned out that "Client Integration" had been turned off.
To enable this (and hopefully resolve your problem), go to your Central Administration and then navigate to Application Management --> Authentication Providers --> Default. On this page, you can enable client integration. For me, that did the trick...
Showing posts with label SharePoint. Show all posts
Showing posts with label SharePoint. Show all posts
Wednesday, February 24, 2010
Thursday, January 14, 2010
Error when deploying a solution
Today I was trying to install one of the "fantastic 40" templates and when I tried deploying the wsp file, the job started running and resulted in an "error" state. There was nothing in the Event Logs and nothing in the ULS logs either. After some reading on the MS forum, I saw a post where someone suggested (for a similar problem) that the Windows SharePoint Services Administration service had to be running. So I restarted this service on all servers and tried to deploy again... and it worked! I don't know if this will apply in all situations where you just get an error when deploying a solution (most likely not), but it's something you can give a try...
Wednesday, December 9, 2009
The detection failed, this can be due to a corrupted installation database
If you ever encounter the above error when trying to install a hotfix or service pack for SharePoint (as I did), then there's a lot of possible answers around, but the right one is quite hard to find, so hopefully, I can help with pointing you in the right direction.
This site helped me a lot with solving the issue, so just go there, follow the second solution and if you're as lucky as I was, it will solve the problem and you'll be able to install hotfixes and all other stuff on your server again!
Thanks to KbNk for posting this!!
This site helped me a lot with solving the issue, so just go there, follow the second solution and if you're as lucky as I was, it will solve the problem and you'll be able to install hotfixes and all other stuff on your server again!
Thanks to KbNk for posting this!!
Thursday, October 15, 2009
Unable to select different display modes in picture library
Just a quick one this time... When you add a Picture Library to SharePoint, you usually can choose between three display modes: filmstrip, details and thumbnail. You can select these through a small menu that appears when you hover over the "All Items" view in the view picker. But what if you don't get this little menu?
This was the case in the environment I was working in. Turned out that this was a bug caused by the installation of the WSS Infrastructure Update. Luckily for all people with this problem, there is a hotfix for this:
http://support.microsoft.com/kb/959644
Just request the hotfix through this page and install it on your front end server and everything should work as it is supposed to work again!
This was the case in the environment I was working in. Turned out that this was a bug caused by the installation of the WSS Infrastructure Update. Luckily for all people with this problem, there is a hotfix for this:
http://support.microsoft.com/kb/959644
Just request the hotfix through this page and install it on your front end server and everything should work as it is supposed to work again!
Labels:
Hotfix,
Infrastructure Update,
Picture Library,
SharePoint
Wednesday, September 23, 2009
Unable to locate the xml-definition for FieldName with FieldId ...
If you're trying to deploy some custom site columns using a feature and the feature activates fine, but the columns don't show up and your logs give you the above error, then the solution is pretty simple: when you're defining your columns, you have to make sure to use brackets around your column guid, like this: {GUID}. Deploy your feature again, deactivate it, activate it again and everything should work fine! You also have to use the brackets when you're referencing the column in a content type!
Thanks to Edwin Vriethoff for posting this!
Thanks to Edwin Vriethoff for posting this!
Tuesday, September 22, 2009
Modify the default scope for your search box
Today I got asked how to modify the search box on a MOSS site so that it displayed "People" by default in stead of "All Sites". The customer already figured out a way to do this with code, but they weren't 100% sure about it. I had to search for this myself too, cause to be honest, I hadn't done this before, even though I'm already working with SharePoint for almost 3 years now... That's why I'm making this short post, so that all the other people who are trying to do this, know how easy it really is.
To modify the default scope, go to your home page and navigate to "Site Actions” --> “Site Settings” --> “Modify All Site Settings". On this page, pick "Search scopes" under the Site Collection Administration. Here you'll see some different "Display groups", one of them is the "Search Dropdown", which is the search box you see on your SharePoint site. If you click on the "Search Dropdown" link, you'll be taken to a page with some settings for this group and the bottom one is where you set your default scope. So modify this to whatever you want, click OK and you're done!
To modify the default scope, go to your home page and navigate to "Site Actions” --> “Site Settings” --> “Modify All Site Settings". On this page, pick "Search scopes" under the Site Collection Administration. Here you'll see some different "Display groups", one of them is the "Search Dropdown", which is the search box you see on your SharePoint site. If you click on the "Search Dropdown" link, you'll be taken to a page with some settings for this group and the bottom one is where you set your default scope. So modify this to whatever you want, click OK and you're done!
Thursday, June 18, 2009
OWSTIMER error when restoring a SharePoint site
When I was trying to restore a web application with a single site in it and one content database, I received the following two errors:
Error: Object OldIntranet (89) (previous name: Intranet (80)) failed in event OnRestore. For more information, see the error log located in the backup directory.
SPUpdatedConcurrencyException: An update conflict has occurred, and you must re-try this action. The object SPWebApplication Name=OldIntranet (89) Parent=SPWebService is being updated by svc_moss_sql, in the OWSTIMER process, on machine MP-MOSS-INDEX01. View the tracing log for more information about the conflict.
Error: Object SharePoint _OldIntranet89_Content (previous name: SharePoint _Intranet_Content) failed in event OnPostRestore. For more information, see the error log located in the backup directory.
SPException: Cannot attach database to Web application. Use the command line tool or Central Administration pages to attach the database manually to the proper Web Application.
I tried every possible solution I found on the internet, but nothing worked. Then I decided to try the update with stsadm through the following command:
stsadm -o restore -directory "\\fileshare\backupfolder" -restoremethod new -item
"Farm\Windows SharePoint Services Web Application\Intranet (80)"
After doing this, I first got a new, different error about the Administration Service. I restarted this service and after that, the stsadm command also gave me the two previous errors. So then I decided to just turn off the Windows SharePoint Services Timer service... and what do you know, it worked! Afterwards, I also noticed that I had turned off the WSS Administration service, so if turning off the Timer service doesn't work, you can also try this one.
I do know that turning off the Timer service in a live environment probably is not such a good idea, but well, if nothing else works, you might be forced to do so...
I also didn't test doing the restore through Central Administration (since it had already been succesfully restored through stsadm), but feel free to give it a shot and let me know if it also works! (Although I doubt it, since I think the procedure through the Central Admin uses a timer job for this, which won't work if the Timer services has been stopped.)
Error: Object OldIntranet (89) (previous name: Intranet (80)) failed in event OnRestore. For more information, see the error log located in the backup directory.
SPUpdatedConcurrencyException: An update conflict has occurred, and you must re-try this action. The object SPWebApplication Name=OldIntranet (89) Parent=SPWebService is being updated by svc_moss_sql, in the OWSTIMER process, on machine MP-MOSS-INDEX01. View the tracing log for more information about the conflict.
Error: Object SharePoint _OldIntranet89_Content (previous name: SharePoint _Intranet_Content) failed in event OnPostRestore. For more information, see the error log located in the backup directory.
SPException: Cannot attach database to Web application. Use the command line tool or Central Administration pages to attach the database manually to the proper Web Application.
I tried every possible solution I found on the internet, but nothing worked. Then I decided to try the update with stsadm through the following command:
stsadm -o restore -directory "\\fileshare\backupfolder" -restoremethod new -item
"Farm\Windows SharePoint Services Web Application\Intranet (80)"
After doing this, I first got a new, different error about the Administration Service. I restarted this service and after that, the stsadm command also gave me the two previous errors. So then I decided to just turn off the Windows SharePoint Services Timer service... and what do you know, it worked! Afterwards, I also noticed that I had turned off the WSS Administration service, so if turning off the Timer service doesn't work, you can also try this one.
I do know that turning off the Timer service in a live environment probably is not such a good idea, but well, if nothing else works, you might be forced to do so...
I also didn't test doing the restore through Central Administration (since it had already been succesfully restored through stsadm), but feel free to give it a shot and let me know if it also works! (Although I doubt it, since I think the procedure through the Central Admin uses a timer job for this, which won't work if the Timer services has been stopped.)
Wednesday, March 18, 2009
Workflow task: Value does not fall within the expected range
If you get the above error when trying to open a task form in a workflow, then read on!
Here's the situation where I got this error: I have a custom approval workflow where one user adds an order request through an InfoPath form. When the form gets submitted, the "IT Approval" group gets assigned the task to approve or reject the order. Also important is that security has been broken so that only the right people can see and approve the tasks. The whole thing is a bit more elaborate than this, but this is basically all you need to know to understand the problem and hopefully recognize it...
Now, if someone in the IT Approval group goes to check his "My Tasks" page, he sees all the tasks assigned to the group. So far, so good... But when he tries opening a task, he gets an error page displaying the "Value does not fall within the expected range" error message.
I've tried many different things, making sure the IT Approval group had contribute access to the task, read access to the site, the task list and the workflow history, but nothing seemed to work. However, there was one place that I missed: the original document.
So if you're facing this problem and you're using custom security, check your InfoPath form (or any other kind of document that triggered the workflow) and make sure the approval user has read access to this file too. I don't know the exact reason for this, but I guess this is because the workflow is copying fields from the original file into the task form and apparently, this only works when the user can read the original file too.
Here's the situation where I got this error: I have a custom approval workflow where one user adds an order request through an InfoPath form. When the form gets submitted, the "IT Approval" group gets assigned the task to approve or reject the order. Also important is that security has been broken so that only the right people can see and approve the tasks. The whole thing is a bit more elaborate than this, but this is basically all you need to know to understand the problem and hopefully recognize it...
Now, if someone in the IT Approval group goes to check his "My Tasks" page, he sees all the tasks assigned to the group. So far, so good... But when he tries opening a task, he gets an error page displaying the "Value does not fall within the expected range" error message.
I've tried many different things, making sure the IT Approval group had contribute access to the task, read access to the site, the task list and the workflow history, but nothing seemed to work. However, there was one place that I missed: the original document.
So if you're facing this problem and you're using custom security, check your InfoPath form (or any other kind of document that triggered the workflow) and make sure the approval user has read access to this file too. I don't know the exact reason for this, but I guess this is because the workflow is copying fields from the original file into the task form and apparently, this only works when the user can read the original file too.
Thursday, March 12, 2009
Debugger: No symbols have been loaded
Just a quick post that can save you a lot of time.... I was debugging a SharePoint workflow that had already been deployed and everything, but it needed some extra changes. I never succeeded in debugging it though and it always gave me the "no symbols have been loaded for this assembly" message. After trying almost everything (restarting the server, rebuilding and deploying everything, clearing the .Net cache, ...), I found a post of someone saying something about "debug mode". Turned out my Visual Studio project was set in "Release" mode by the one who installed the application and you can't debug when it's in Release mode. To reset this, simply right click on your solution name, choose properties, click on "Configuration Properties" and under "Configuration", select "Debug" for all your projects. Then rebuild and deploy again (make sure you use the .dll files from the "debug" directory in stead of the "release" directory) and everything should debug fine again...
Labels:
debug mode,
Debugging,
No Symbols,
release mode,
SharePoint
Friday, June 27, 2008
The specified name is already in use.
If the above error looks familiar and you can't seem to get rid of it, then read on, I might have a solution for you then!
When trying to activate a feature that would create a list, I received the following error:
The specified name is already in use.
A list, survey, discussion board, or document library cannot have the same name as another list, survey, discussion board, or document library in this Web site.
Use your browser's Back button, and type a new name.
The biggest problem was that the list really didn't exist. When I went to "All Site Content", nothing was there with the name of the list I was creating. I also looped over all my lists with three lines of code I quickly wrote, but nothing there either... After some searching on our good friend Google, I learned that apparently, if you open the site with SharePoint Designer, there is a folder there with that name. Just delete the folder and everything works fine again...
But what if you don't have SharePoint Designer installed and you can't intall it immediately, like me? Well, then these few lines of code might help you out:
SPSite site = null;
SPWeb web = null;
using (site = new SPSite(siteURL))
{
using (web = site.OpenWeb())
{
web.Folders[nameOfListToCreate].Delete();
}
}
When trying to activate a feature that would create a list, I received the following error:
The specified name is already in use.
A list, survey, discussion board, or document library cannot have the same name as another list, survey, discussion board, or document library in this Web site.
Use your browser's Back button, and type a new name.
The biggest problem was that the list really didn't exist. When I went to "All Site Content", nothing was there with the name of the list I was creating. I also looped over all my lists with three lines of code I quickly wrote, but nothing there either... After some searching on our good friend Google, I learned that apparently, if you open the site with SharePoint Designer, there is a folder there with that name. Just delete the folder and everything works fine again...
But what if you don't have SharePoint Designer installed and you can't intall it immediately, like me? Well, then these few lines of code might help you out:
SPSite site = null;
SPWeb web = null;
using (site = new SPSite(siteURL))
{
using (web = site.OpenWeb())
{
web.Folders[nameOfListToCreate].Delete();
}
}
Friday, March 7, 2008
Filtering on multiple values with SPGridView
If you want to show list data in a Web Part, one of the options to consider is using the SPGridView control. There is a nice article on Bob's SharePoint Bonanza on how to set this up. This really is a great article, but it won't allow you to filter on multiple columns. My customer wanted to be able to do this though and he also wanted the Web Part to remember the filtering and sorting options when leaving the page.
I was able to make this work using custom Web Part properties. Here's how to do it:
- First, set up your SPGridvVew and it's datasource as described in Bob's article. When you're done, also add a private string to your Web Part. This string will remember the previous filter.
private string prevFilter = "";
Next, find the following line in the SetupObjectDataSource method:
dataSource.FilterExpression = (string)ViewState["FilterExpression"];
Below this line, add the following line:
prevFilter = dataSource.FilterExpression;
- Your next step is to create two custom properties: one for the filter settings and one for sorting.
private string userSettingsFilter;
private string userSettingsSort;
///
///Hidden property to remember filtering options set by the user
///
[Browsable(false), Category("Advanced"),
DefaultValue(""),
Personalizable(PersonalizationScope.User),
FriendlyName("User Settings Filter"), Description("Hidden user settings for filtering.")]
public string UserSettingsFilter
{
get
{
return userSettingsFilter;
}
set
{
userSettingsFilter = value;
}
}
///
///Hidden property to remember sorting options set by the user
///
[Browsable(false), Category("Advanced"),
DefaultValue(""),
Personalizable(PersonalizationScope.User),
FriendlyName("User Settings Sort"), Description("Hidden user settings for sorting.")]
public string UserSettingsSort
{
get
{
return userSettingsSort;
}
set
{
userSettingsSort = value;
}
}
- In the OnPreRender method, you first check if there is a sort expression set. If this is the case, then save it. Next, check the filter that has been saved to the ViewState. Depending on the column title (is there already a filter on that column or not), save the filter setting to the custom filter property by appending it with either " and " or " or ".
protected override void OnPreRender(EventArgs e)
{
//Check if there is a sort expression set. If this is the case: save it.
if (gridView.SortExpression != "")
{
userSettingsSort = gridView.SortExpression + "&" + gridView.SortDirection;
}
//Get the filter expression into the viewstate. If a filter is set, add it to the saved filter expression.
ViewState["FilterExpression"] = dataSource.FilterExpression;
if (prevFilter != string.Empty && ViewState["FilterExpression"].ToString() == string.Empty)
{
userSettingsFilter = "";
}
if (ViewState["FilterExpression"].ToString() != "")
{
if (userSettingsFilter != null)
{
if (userSettingsFilter != "")
{
//If there already is a filter on a certain column and the user adds another value of this column,
//add it with an "or" expression
if (userSettingsFilter.Contains(ViewState["FilterExpression"].ToString().Substring(0, ViewState["FilterExpression"].ToString().IndexOf('=') + 1)))
{
int tempIndex = userSettingsFilter.IndexOf(ViewState["FilterExpression"].ToString().Substring(0, ViewState["FilterExpression"].ToString().IndexOf('=') + 1));
userSettingsFilter = userSettingsFilter.Insert(tempIndex, "(");
string tempSettings = userSettingsFilter.Substring(tempIndex);
if (tempSettings.Contains(" and "))
{
userSettingsFilter = userSettingsFilter.Insert(tempIndex + tempSettings.IndexOf(" and "), " or " + ViewState["FilterExpression"] + ") ");
}
else
{
userSettingsFilter = userSettingsFilter.Insert(tempIndex + tempSettings.Length, " or " + ViewState["FilterExpression"] + ") ");
}
}
else
{
userSettingsFilter = userSettingsFilter + " and " + ViewState["FilterExpression"].ToString();
}
}
else
{
userSettingsFilter = ViewState["FilterExpression"].ToString();
}
}
else
{
userSettingsFilter = ViewState["FilterExpression"].ToString();
}
}
//Save the changed properties
this.SetPersonalizationDirty();
base.OnPreRender(e);
}
- Next, in the Render method, use the saved filter settings on the datasource's FilterExpression. If a sort setting has been saved, sort the gridview either ascending or descending (depending on the text in the saved setting) on the saved column.
protected override void Render(HtmlTextWriter writer)
{
dataSource.FilterExpression = userSettingsFilter;
if (userSettingsSort != null)
{
if (userSettingsSort != "")
{
if (userSettingsSort.ToLower().Contains("ascending"))
{
gridView.Sort(userSettingsSort.Substring(0, userSettingsSort.IndexOf('&')), SortDirection.Ascending);
}
else
{
gridView.Sort(userSettingsSort.Substring(0, userSettingsSort.IndexOf('&')), SortDirection.Descending);
}
}
}
gridView.DataBind();
base.Render(writer);
}
There are a few disadvantages when using this method though. Your list won't show icons showing which columns are being filtered on and you will only get the option to remove the filter you've last set. Due to this, removing that last filter value, will automatically remove all filters. Also, if you go away from the page and then return, you won't have the option to undo the filter and you will have no indication that there is a filter enabled (except for the fact that not all fields are shown). To remove this filter, you need to set an extra filter and then remove it again, so all filter options are cleared. Another disadvantage is when you set your filter options in a certain way that no data is shown, your heading will disappear and you won't be able to clear the filter anymore, so you'll be stuck with an empty SPGridView forever. To solve this, you can either make the custom filter property visible, so you can edit your Web Part and manually remove the filter, or you can add a button to the Web Part that clears the filter for you.
A better way of implementing this is rendering the view as html (see one of my previous posts). This way, the list will have the same look and feel as a default SharePoint list. I think that this last solution is better in almost every way, but for some situations you might need to use the SPGridView, for example when you need to use a certain datasource (which was the situation I was in, it was impossible for me to display the same data that I got from the datasource) and with this implementation, you're also able to filter on multiple values of one column, which is not possible with the default SharePoint list.
If you have any comments, remarks, possible improvements or questions, just shoot!
I was able to make this work using custom Web Part properties. Here's how to do it:
- First, set up your SPGridvVew and it's datasource as described in Bob's article. When you're done, also add a private string to your Web Part. This string will remember the previous filter.
private string prevFilter = "";
Next, find the following line in the SetupObjectDataSource method:
dataSource.FilterExpression = (string)ViewState["FilterExpression"];
Below this line, add the following line:
prevFilter = dataSource.FilterExpression;
- Your next step is to create two custom properties: one for the filter settings and one for sorting.
private string userSettingsFilter;
private string userSettingsSort;
///
///Hidden property to remember filtering options set by the user
///
[Browsable(false), Category("Advanced"),
DefaultValue(""),
Personalizable(PersonalizationScope.User),
FriendlyName("User Settings Filter"), Description("Hidden user settings for filtering.")]
public string UserSettingsFilter
{
get
{
return userSettingsFilter;
}
set
{
userSettingsFilter = value;
}
}
///
///Hidden property to remember sorting options set by the user
///
[Browsable(false), Category("Advanced"),
DefaultValue(""),
Personalizable(PersonalizationScope.User),
FriendlyName("User Settings Sort"), Description("Hidden user settings for sorting.")]
public string UserSettingsSort
{
get
{
return userSettingsSort;
}
set
{
userSettingsSort = value;
}
}
- In the OnPreRender method, you first check if there is a sort expression set. If this is the case, then save it. Next, check the filter that has been saved to the ViewState. Depending on the column title (is there already a filter on that column or not), save the filter setting to the custom filter property by appending it with either " and " or " or ".
protected override void OnPreRender(EventArgs e)
{
//Check if there is a sort expression set. If this is the case: save it.
if (gridView.SortExpression != "")
{
userSettingsSort = gridView.SortExpression + "&" + gridView.SortDirection;
}
//Get the filter expression into the viewstate. If a filter is set, add it to the saved filter expression.
ViewState["FilterExpression"] = dataSource.FilterExpression;
if (prevFilter != string.Empty && ViewState["FilterExpression"].ToString() == string.Empty)
{
userSettingsFilter = "";
}
if (ViewState["FilterExpression"].ToString() != "")
{
if (userSettingsFilter != null)
{
if (userSettingsFilter != "")
{
//If there already is a filter on a certain column and the user adds another value of this column,
//add it with an "or" expression
if (userSettingsFilter.Contains(ViewState["FilterExpression"].ToString().Substring(0, ViewState["FilterExpression"].ToString().IndexOf('=') + 1)))
{
int tempIndex = userSettingsFilter.IndexOf(ViewState["FilterExpression"].ToString().Substring(0, ViewState["FilterExpression"].ToString().IndexOf('=') + 1));
userSettingsFilter = userSettingsFilter.Insert(tempIndex, "(");
string tempSettings = userSettingsFilter.Substring(tempIndex);
if (tempSettings.Contains(" and "))
{
userSettingsFilter = userSettingsFilter.Insert(tempIndex + tempSettings.IndexOf(" and "), " or " + ViewState["FilterExpression"] + ") ");
}
else
{
userSettingsFilter = userSettingsFilter.Insert(tempIndex + tempSettings.Length, " or " + ViewState["FilterExpression"] + ") ");
}
}
else
{
userSettingsFilter = userSettingsFilter + " and " + ViewState["FilterExpression"].ToString();
}
}
else
{
userSettingsFilter = ViewState["FilterExpression"].ToString();
}
}
else
{
userSettingsFilter = ViewState["FilterExpression"].ToString();
}
}
//Save the changed properties
this.SetPersonalizationDirty();
base.OnPreRender(e);
}
- Next, in the Render method, use the saved filter settings on the datasource's FilterExpression. If a sort setting has been saved, sort the gridview either ascending or descending (depending on the text in the saved setting) on the saved column.
protected override void Render(HtmlTextWriter writer)
{
dataSource.FilterExpression = userSettingsFilter;
if (userSettingsSort != null)
{
if (userSettingsSort != "")
{
if (userSettingsSort.ToLower().Contains("ascending"))
{
gridView.Sort(userSettingsSort.Substring(0, userSettingsSort.IndexOf('&')), SortDirection.Ascending);
}
else
{
gridView.Sort(userSettingsSort.Substring(0, userSettingsSort.IndexOf('&')), SortDirection.Descending);
}
}
}
gridView.DataBind();
base.Render(writer);
}
There are a few disadvantages when using this method though. Your list won't show icons showing which columns are being filtered on and you will only get the option to remove the filter you've last set. Due to this, removing that last filter value, will automatically remove all filters. Also, if you go away from the page and then return, you won't have the option to undo the filter and you will have no indication that there is a filter enabled (except for the fact that not all fields are shown). To remove this filter, you need to set an extra filter and then remove it again, so all filter options are cleared. Another disadvantage is when you set your filter options in a certain way that no data is shown, your heading will disappear and you won't be able to clear the filter anymore, so you'll be stuck with an empty SPGridView forever. To solve this, you can either make the custom filter property visible, so you can edit your Web Part and manually remove the filter, or you can add a button to the Web Part that clears the filter for you.
A better way of implementing this is rendering the view as html (see one of my previous posts). This way, the list will have the same look and feel as a default SharePoint list. I think that this last solution is better in almost every way, but for some situations you might need to use the SPGridView, for example when you need to use a certain datasource (which was the situation I was in, it was impossible for me to display the same data that I got from the datasource) and with this implementation, you're also able to filter on multiple values of one column, which is not possible with the default SharePoint list.
If you have any comments, remarks, possible improvements or questions, just shoot!
Labels:
Custom properties,
filtering,
multiple values,
SharePoint,
SPGridView
Monday, January 14, 2008
Error: “Cannot find the path specified” when adding role assignments
If you ever get the error “The system cannot find the path specified. (Exception from HRESULT: 0x80070003)” while adding role assignments to a library or web in SharePoint, then this might help you solve your problem… I was trying to add role assignments to a library (using library.RoleAssignments.Add(newRole)), which had already worked perfectly before, but when trying it this time, I got the error I’ve mentioned before. The key to solving my issue was something that didn’t include paths at all: I just forgot to break the role inheritance of my library. So if you ever encounter this error, just add the following lines, they will most probably solve your issue:
library.BreakRoleInheritance(true);
library.Update();
library.BreakRoleInheritance(true);
library.Update();
Labels:
Cannot find the path,
Role Assignments,
SharePoint
Monday, February 5, 2007
How to add a BestBet in SharePoint 2007 programmatically
First of all: hi! I'm Tom, software engineer at Dolmen (you know, the company where the infamous jopx works, not by coïncidence the person who I report to...). It took me a while to start blogging, but when I was looking for information on adding BestBets and Keywords programmatically and I couldn't find a thing, it just felt like the right moment to start a blog and "share the wisdom" as they say. Adding Keywords and BestBets is actually not that difficult, you just have to know the right syntax to do so. That's where I come in: here's what I did to make it work:
Now let's explain what this code does...
To start off, we create a boolean that tells us whether the Keyword we want to add a BestBet for is already in the Keywordcollection or not. If it isn't, we'll add it at the end of our code.
The next step is to get all the Keywords of the current Sitecollection you are working on. To do so, we need to create a new Keywordcollection with the context of the current Sitecollection and the url of this Sitecollection.
Once we've found the Keywords, we're going to browse through all the Keywords of the current Sitecollection to check for a match with the Keyword you want to add a BestBet for (in the example I've just used "textToCompareTo" as the string we're looking for). If we find this Keyword in the Keywordcollection, we're going to browse through all the BestBets that have been assigned to this Keyword, to check whether the BestBet we want to add is already part of the BestBetcollection or not. If it is, then our job is done and we don't have to do a thing anymore. If it isn't, we'll add it by creating a new BestBet with a certain title, description and an url we want the BestBet to refer to.
So there you go, not that hard as I first thought it was going to be. If there's any questions or remarks, feel free to leave a comment.
bool found = false;
Keywords keys = new Keywords(SearchContext.GetContext(SPContext.Current.Site), new Uri(SPContext.Current.Site.Url));
foreach (Keyword key in keys.AllKeywords)
{
if (key.Term.ToLower() == textToCompareTo.ToLower())
{
found = true;
bool foundBet = false;
foreach (BestBet bet in key.BestBets)
{
if (bet.Url == urlToReferTo)
{
foundBet = true;
}
}
if (!foundBet)
{
key.BestBets.Create("Title", "BestBet description", urlToReferTo);
}
break;
}
}
if (!found)
{
keys.AllKeywords.Create(textToCompareTo.ToLower(), DateTime.Now);
}Now let's explain what this code does...
To start off, we create a boolean that tells us whether the Keyword we want to add a BestBet for is already in the Keywordcollection or not. If it isn't, we'll add it at the end of our code.
The next step is to get all the Keywords of the current Sitecollection you are working on. To do so, we need to create a new Keywordcollection with the context of the current Sitecollection and the url of this Sitecollection.
Once we've found the Keywords, we're going to browse through all the Keywords of the current Sitecollection to check for a match with the Keyword you want to add a BestBet for (in the example I've just used "textToCompareTo" as the string we're looking for). If we find this Keyword in the Keywordcollection, we're going to browse through all the BestBets that have been assigned to this Keyword, to check whether the BestBet we want to add is already part of the BestBetcollection or not. If it is, then our job is done and we don't have to do a thing anymore. If it isn't, we'll add it by creating a new BestBet with a certain title, description and an url we want the BestBet to refer to.
So there you go, not that hard as I first thought it was going to be. If there's any questions or remarks, feel free to leave a comment.
Subscribe to:
Posts (Atom)
