I had a problem on a server to access the Active Directory. The error-message led to the following method:
Server stack trace:
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
When debugging, I got the error that the Context was null.
What saved my day was to wrap the whole Active Directory performance into an impersonation.
using(HostingEnvironment.Impersonate())
{
My active directory code
}
Mittwoch, 26. Juni 2013
Donnerstag, 11. April 2013
Resource file usage in SharePoint 2010 with Visual Studio 2010
There are two ways to use resource files in SharePoint.
One is with code-behind and the other is to render it in the control.
In the following image you see version (1) in line 9 and version (2) in line 10

Version 1 requires a resx file in the SharePoint 14 hive 'Resources' folder.
Version 2 requires a deployment to App_GlobalResources folder.
Important, if you want to have your resx file to deployed to the 14 hive, first map your project with the SharePoint Resources folder. Then place your resx file in there and you will need to set the Build Action in the resx property to 'Content' otherwise a deployment to the hive won't take place (file will not be physically copied to the hive folder).

Next thing is to click on your feature and set there the property 'DefaultResourceFile' to the neutral resource file and set 'Require Resources' to true.

How to deploy to the App_GlobalResources:
Create in your SharePoint 2010 project a new item "Empty Element". I called it 'ResourceFiles'.
Then you place your resource file in there. To test properly I named it the same and also added the same key with a different value.

When checking the properties of the resx file, set the Deployment Type to 'AppGlobalResource'

Deploy your solution and then check the result.
In my case according to that code

I had this result
One is with code-behind and the other is to render it in the control.
In the following image you see version (1) in line 9 and version (2) in line 10
Version 1 requires a resx file in the SharePoint 14 hive 'Resources' folder.
Version 2 requires a deployment to App_GlobalResources folder.
Important, if you want to have your resx file to deployed to the 14 hive, first map your project with the SharePoint Resources folder. Then place your resx file in there and you will need to set the Build Action in the resx property to 'Content' otherwise a deployment to the hive won't take place (file will not be physically copied to the hive folder).
Next thing is to click on your feature and set there the property 'DefaultResourceFile' to the neutral resource file and set 'Require Resources' to true.
How to deploy to the App_GlobalResources:
Create in your SharePoint 2010 project a new item "Empty Element". I called it 'ResourceFiles'.
Then you place your resource file in there. To test properly I named it the same and also added the same key with a different value.
When checking the properties of the resx file, set the Deployment Type to 'AppGlobalResource'
Deploy your solution and then check the result.
In my case according to that code
I had this result
Donnerstag, 14. März 2013
ULS Viewer no items
I had the problem, that when I started ULS Viewer, no items where displayed.
Then checking the 14-hive of SharePoint and the log folder, all log files had 0 KB size.
When checking the SharePoint log-settings, everything was set properly.
The problem was, that the disc space ran out. I cleared the disc, so I had at least 1,2 GB space.
I restarted the SharePoint 2010 Tracing (Windows) service.
Then I deleted all the old 0 KB files in the log folder and voila, logs were written to the files and ULS viewer could display them.
Dienstag, 27. November 2012
PublishingWeb unable to create page
I ran into a problem, where I wanted to create a page through PowerShell and then I received errors, when using the PublishingWeb object.
After a while I figured out, that you need to enable the web-scoped feature: SharePoint Server Publishing - 94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb
and then you might have to check if the web, does have a property-bag key "__PagesListId".
If not, create a key and save there the Guid of the document library, where you save the pages in. Default en-US install is "Pages"-library.
If you already do have the key, make sure, that the value corresponds to the Guid of the library, you save the pages in.
After a while I figured out, that you need to enable the web-scoped feature: SharePoint Server Publishing - 94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb
and then you might have to check if the web, does have a property-bag key "__PagesListId".
If not, create a key and save there the Guid of the document library, where you save the pages in. Default en-US install is "Pages"-library.
If you already do have the key, make sure, that the value corresponds to the Guid of the library, you save the pages in.
Dienstag, 22. Mai 2012
Delete items from a SPListItemCollection
Just a really dumb error I made when deleting items from a SPListItemCollection.
This is my code:
SPListItemCollection listCollection = list.GetItems(spQuery);
for (int i = 0; i < listCollection.Count; i++)
{
listCollection.Delete(i); //listCollection.Delete(0)
}
What I did before was to go through the Count() method of the list-item-collection. This is wrong, because the amount of Count() changes during this operation. That means, not everything will be deleted. Use the code bellow. It will loop really through each item and will delete the dynamically changed first item of the list-collection.
SPListItemCollection listCollection = list.GetItems(spQuery);
int counter = listCollection.Count;
for (int i = 0; i < counter; i++)
{
listCollection.Delete(0);
}
That means you should be aware, that the index and the Count() method change, when performing a Delete() operation.
SPListItemCollection listCollection = list.GetItems(spQuery);
for (int i = 0; i < listCollection.Count; i++)
{
listCollection.Delete(i); //listCollection.Delete(0)
}
What I did before was to go through the Count() method of the list-item-collection. This is wrong, because the amount of Count() changes during this operation. That means, not everything will be deleted. Use the code bellow. It will loop really through each item and will delete the dynamically changed first item of the list-collection.
SPListItemCollection listCollection = list.GetItems(spQuery);
int counter = listCollection.Count;
for (int i = 0; i < counter; i++)
{
listCollection.Delete(0);
}
That means you should be aware, that the index and the Count() method change, when performing a Delete() operation.
Freitag, 2. März 2012
SharePoint Webtemplate deployment error
When you want to deploy a webtemplate through Visual Studio and you get the following error:
"Error occurred in deployment step 'Add Solution': Exception from HRESULT: 0x8107026E"
Then you have just a naming problem. The WebTemplate Name-Attribute needs to have the same name as the EmptyElement folder-name.
"Error occurred in deployment step 'Add Solution': Exception from HRESULT: 0x8107026E"
Then you have just a naming problem. The WebTemplate Name-Attribute needs to have the same name as the EmptyElement folder-name.
Mittwoch, 29. Februar 2012
Error when deploying out of Visual Studio
I received an error when trying to deploy out of Visual Studio:
Error occurred in deployment step 'Activate Features':0x80070005
The issue that caused this error was, that the user I was logged on my Windows, did not have administrative rights in the site-collection I wanted to deploy to.
I added my Windows user as an site-collection administrator and Voila, it worked.
Error occurred in deployment step 'Activate Features':
The issue that caused this error was, that the user I was logged on my Windows, did not have administrative rights in the site-collection I wanted to deploy to.
I added my Windows user as an site-collection administrator and Voila, it worked.
Montag, 27. Februar 2012
Web templates HRESULT: 0x81070215
I wanted to create a web-template in Sharepoint 2010. This was supposed to substitude my site-definition. When trying to deploy, I received the error on "Add solution" with the error-code: HRESULT: 0x81070215.
I figured out, that I had the onet.xml in my folder, the elements.xml in my folder, but did not set the Deployment-type of the onet.xml correctly. Therefore go to the properties of the onet.xml and set it there. Check out the screenshot below:

I figured out, that I had the onet.xml in my folder, the elements.xml in my folder, but did not set the Deployment-type of the onet.xml correctly. Therefore go to the properties of the onet.xml and set it there. Check out the screenshot below:
Montag, 13. Februar 2012
How to get the IIS-directory of a webapplication with Powershell
There might be the need to get the IIS absolute path of your webapplication.
Here is the Powershell-script with which you can achieve that:
function GetIISPath ([string] $webApplicationName)
{
foreach($app in Get-SPWebApplication)
{
if($app.Name -eq $webApplicationName)
{
$IISSettings = $app.IisSettings[[Microsoft.SharePoint.Administration.SPUrlZone]::Default]
Write-Host $IISSettings.Path
}
}
}
This function writes the absolute path of the overloaded webapplication-name.
Here is the Powershell-script with which you can achieve that:
function GetIISPath ([string] $webApplicationName)
{
foreach($app in Get-SPWebApplication)
{
if($app.Name -eq $webApplicationName)
{
$IISSettings = $app.IisSettings[[Microsoft.SharePoint.Administration.SPUrlZone]::Default]
Write-Host $IISSettings.Path
}
}
}
This function writes the absolute path of the overloaded webapplication-name.
Mittwoch, 8. Februar 2012
value does not fall within the expected range -> Sharepoint list
I had the following code:
public static SPListItemCollection GetListItemCollection(string query)
{
SPListItemCollection listitemcollection = null;
SPList list = web.Lists["TestList"];
listitemcollection = list.GetItems(query);
return listitemcollection;
}
the issue was, that I did receive a SPListItemCollection object, but with no fileds in it, when debugging. When trying to access the field, the error displayed was:
I solved the problem in adding a SPQuery object to it. It seems, that the GetItems() method-overload, does not accept the query-string as a string overload. You need to pass it into the property of the SPQuery object and then overload with the object. This worked like a charm. Here the code:
public static SPListItemCollection GetListItemCollection(string query)
{
SPListItemCollection listitemcollection = null;
SPList list = web.Lists["TestList"];
SPQuery spquery = new SPQuery();
spquery.Query = query;
listitemcollection = list.GetItems(spquery);
return listitemcollection;
}
public static SPListItemCollection GetListItemCollection(string query)
{
SPListItemCollection listitemcollection = null;
SPList list = web.Lists["TestList"];
listitemcollection = list.GetItems(query);
return listitemcollection;
}
the issue was, that I did receive a SPListItemCollection object, but with no fileds in it, when debugging. When trying to access the field, the error displayed was:
I solved the problem in adding a SPQuery object to it. It seems, that the GetItems() method-overload, does not accept the query-string as a string overload. You need to pass it into the property of the SPQuery object and then overload with the object. This worked like a charm. Here the code:
public static SPListItemCollection GetListItemCollection(string query)
{
SPListItemCollection listitemcollection = null;
SPList list = web.Lists["TestList"];
SPQuery spquery = new SPQuery();
spquery.Query = query;
listitemcollection = list.GetItems(spquery);
return listitemcollection;
}
Abonnieren
Posts (Atom)