Posts mit dem Label Sharepoint werden angezeigt. Alle Posts anzeigen
Posts mit dem Label Sharepoint werden angezeigt. Alle Posts anzeigen

Freitag, 17. Januar 2014

SharePoint picture library properties

I wanted to post a useful information about properties of SharePoint picutre libraries.

ServerUrl = /sites/mysite/MyPictures/logo.jpg
EncodedAbsUrl = http://www.mydomain.com/sites/mysite/MyPictures/logo.jpg
FileRef = /sites/mysite/MyPictures/logo.jpg
FileLeafRef = logo.jpg
EncodedAbsThumbnailUrl = http://www.mydomain.com/sites/mysite/MyPictures/_t/logo_jpg.jpg
EncodedAbsWebImgUrl = http://www.mydomain.com/sites/mysite/MyPictures/_w/logo_jpg.jpg

Dienstag, 17. Dezember 2013

Cannot start service spusercodev4 on computer

I tried to deploy a sandbox solution out of Visual Studio 2010 and received the following error:
cannot start service spusercodev4 on computer
Somehow the "Microsoft SharePoint Foundation Sandboxed Code Service" in Central Administration stopped.
Go to Central Administration -> System Settings -> Manage services on server and pick there the service mentioned above and restart. I read on another blog, that also the "Microsoft SharePoint Foundation User Code Service" service might cause this trouble. If my solution does not work, please refer to this blog:
http://blog.dennus.net/2009/11/18/sp2010-spusercodev4-your-new-web-part-project-isnt-deploying/

Donnerstag, 21. November 2013

Custom field type -error

I had a .NET Error when creating a custom field type in my SharePoint list:
Microsoft.SharePoint.SPException: Field type FolderField is not installed properly. Go to the list settings page to delete this field.
at Microsoft.SharePoint.SPFieldCollection.GetDotNetTypeForFieldType(String typeName)
at Microsoft.SharePoint.SPFieldCollection.CreateNewFieldInternal(String typeName, String displayName)
at Microsoft.SharePoint.ApplicationPages.FieldNewPage.Save()

Reason therefore was an error in my fldtypes_MyCustomField.xml.
There I had a wrong FieldTypeClass. It should be this way:
<Field Name="FieldTypeClass">[Class with Namespace Test.MyCustomField], [Assembly-name], Version=1.0.0.0, Culture=neutral, PublicKeyToken=b426d5u8827cb6b6</Field>

Montag, 14. Oktober 2013

file.OpenBinary() - access denied

I ran over an error, which can be confusing. I wanted to get a file in SharePoint 2010 programmatically and suddenly I received the error at file.OpenBinary(), that the access is denied. I checked all the permission and was even more confused, because everything was set correctly. I was accessing via elevated privilages and this made me wonder even more.
The solution was really simple. The path to the file was wrong. Usually I would expect a file not found error message in SharePoint, but it seems an access denied is thrown in this case.
The path was not wrong in a matter, that the library was not existing, it was more, that the path went deeper in the folder structure than there was any existing in the library.

Donnerstag, 10. Oktober 2013

Secure Store Service SharePoint 2010 GetCredentials Access denied

I had the problem, that I wanted to impersonate to SecureStoreService of SharePoint 2010 programmatically, but received an access denied at the point where the method GetCredentials is called.
This happen to me twice in different scenarios:
1. I tried to impersonate in an Elevated environment. Of course, then the used system account has to be also a member of the SecureStoreService.
2. I undid the impersonation after the code sequence and it seems having different methods calling other methods, impersonated and undid and the wrong place, when other methods tried to access.
That means, be aware which account is currently running the code and that this account is also a member of the SecureStoreService.
Try to keep the impersonation area as small as possible, to impersonation does not interfere with other impersonation-efforts.


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

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.

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.

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.

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.

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:



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;
}


Dienstag, 7. Juni 2011

Webpart maintenance page

If you are running into the problem, that you added a webpart to your page and you want to remove it, because it breaks your page, then just add the query-string ?contents=1 to your URL and it will redirect you to the webpart maintenance page.

Webpart maintenance page

If you are running into the problem, that you added a webpart to your page and you want to remove it, because it breaks your page, then just add the query-string ?contents=1 to your URL and it will redirect you to the webpart maintenance page.

Mittwoch, 18. Mai 2011

Cannot generate serialization assembly ... Use /force to force an overwrite

I received this error when trying to deploy something to Sharepoint. The issue seems to be, that the dll is locked by some procedure of the IIS. Just perform in the command line a "iisreset" and try again.
Sometimes you also have to close Visual Studio and re-open after the iisreset and try again.

Donnerstag, 14. April 2011

How to get the default page of a site

It is not always necessary to have the default page of a site called default.aspx.
You can use a page called mypage.aspx and use this one as default.

But when you iterate through a site, how do you find out, which page is the default one. Therefore use a code like this to find out.

First you need a SPWeb object of your site-url (e.g. your site-url is http://www.yourwebapp.com/yoursite/yoursubsite/)

string result = string.Empty;
SPSecurity.RunWithElevatedPrivileges(delegate{
SPWeb web = SPContext.Current.Site.OpenWeb("yoursite/yoursubsite");
result = web.RootFolder.WelcomePage;
});

The result value will be "Pages/mypage.aspx".

Dienstag, 29. März 2011

Variations Display Name vs. Label

Always good to know.
Display Name is the name shown in the structure tree and the name of the site.
The label is the name of the variation.

Montag, 28. März 2011

How to: c# code in powershell script

I was looking for a way to add C# code to a powershell script, because sometimes you are not able to run everything with powershell.
It works like this:

first reference to the assemblies your code uses:
$referencingassemblies = (
"Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" ,
"Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c",
"System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
)


Then insert the source and store it in a variable. Be aware to have all the assemblies you are using referenced in your variable above:
$mysource = @"
using Microsoft.SharePoint.Publishing.Administration;
using Microsoft.SharePoint;
using System;
using System.Data;
using System.Xml;
using Microsoft.SharePoint.Publishing;

namespace MyNamespace
{
public static class MyClass
{
public static void Do(SPWeb rootWeb)
{
Console.WriteLine(rootWeb.Url);
Console.WriteLine(rootWeb.Title);
}
}
}
"@


Then add the code to the memory and call your code:
#Here you just add the assemblies and the code to the memory
Add-Type -ReferencedAssemblies $referencingassemblies -TypeDefinition $mysource -Language CSharp
#For this sample I will need another assembly
[system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint")
#Load the site-object of your webapp
$site = New-Object Microsoft.SharePoint.SPSite("http://www.mydomain.com")
#Use the rootweb of your site
$root = $site.rootweb
#Overload to your C# method. To call the method use in brakets the namespace and class.
[MyNamespace.MyClass]::Do($root)

In this sample above you already see how to combine powershell code with C# code. If you change something in your C# code, then close the powershell window and re-open, so the code will be loaded/added to memory again. Otherwise you won't see the changes you made.
You can copy the code-segments above into one powershell script file and give it a try.

Donnerstag, 3. März 2011

Powershell - site-defintion installation

I had the following problem. I created a powershell script to install a solution, that contains a site-defintion to a web-application. The issue I ran into was, that the template I am using to create the SPSite in this web-application was not recognized. That means everytime I tried to use this custom template, I received the error ""

On the web I found the cause for this error. The template is not recognized in this session. When you open parallel another powershell window and list the templates (get-spwebtemplates), then you see your template. But not in the host window.

To avoid this error, you have to start another powershell process out of the host window. There you can work with the template.
Be aware to add a sleep function, because the install of the solution with the site-definition needs to be terminated before being able to work with it.

You can copy the host-script into a file called hostscript.ps1 and the new window script into a file called window.ps1

---- your host script ------- (rename the %% variables with your parameters)
#This function installs the solution
function InstallSolution([string] $solutionname, [string] $url)
{
#Check if solution already exists
$solution = Get-SPSolution | where-object {$_.Name -eq $solutionname}
if ($solution -eq $null)
{
#If it is not added yet. Add it and then deploy it.
Add-SPSolution -LiteralPath "%your solution directory%\$solutionname"
Install-SPSolution –Identity $SolutionName –WebApplication "http://$url" –GACDeployment
}
$solution = Get-SPSolution | where-object {$_.Name -eq $solutionname}
#Run the sleeper. It will wait until the solution is finally deployed
do
{
Start-Sleep -Seconds 10
}
until ($solution.Deployed -eq $true)
}

#Enter your parameters here
$webapplicationname = %webapplication-name%
$webapplicationport = %webapplication-port%
$hostheader = %host-header%
$url = %url%
$iisdirectory = %iis-directory%
$apppool = %app-pool%
$apppoolaccount = %app-pool-account%
$databasename = %database-name%
$databaseserver = %database-server%
$sitecollectionadmin = %site-collection-admin%

#Create a new web-application with the above mentioned parameters
New-SPWebApplication -Name $webapplicationname -Port $webapplicationport -AllowAnonymousAccess:$true -HostHeader $hostheader -URL "http://$url" -Path $iisdirectory -ApplicationPool $apppool -ApplicationPoolAccount (Get-SPManagedAccount $apppoolaccount) -DatabaseName $databasename -DatabaseServer $databaseserver

#Call the function above and overload the needed parameters
InstallSolution "%my solution name%", $url

#Here is your template-name. If you don't know yours, then just install the solution and run get-spwebtemplate. It lists all templates. Yours is then supposed to be there as well with the correct # value.
$mydefinitiontemplate = "%My Template%#0"

#Here the new console powershell-window opens.
$newwindow = New-Object system.Diagnostics.ProcessStartInfo
$newwindow.FileName = "powershell.exe"
#I am overloading some variables just to show, how this works
$newwindow.Arguments = "-noexit %your install directory%\window.ps1 $url $mydefinitiontemplate $sitecollectionadmin"
$process = [system.Diagnostics.Process]::Start($newwindow)
#The process will wait, until the window will exit and close
$process.waitforexit()

#Finally just reset the iis
iisreset

---- end host script -------


---- your new window script ------- (rename the %% variables with your parameters)
#Here you catch the overloaded parameters and fill some variables with it
$url = $args[0]
$mytemplatename = $args[1]
$sitecollectionadmin = $args[2]

#Create the new site-collection
New-SPSite -URL "http://$url" -OwnerAlias $sitecollectionadmin -Name %your site name% -Template $mytemplatename
#Tell the host-window, that this window closed
$Host.SetShouldExit(0)

---- end new window script -------

Then save those files somewhere and open powershell and type:
[your path of the hostscript.ps1 file]\hostscript.ps1

This script now creates the web-application, installs the solution with the site-definition and as soon as the solution is deployed, it opens a new console window, to run the second script, that creates a new site-collection in the web-application with the site-definition template you deployed. The window closes afterwards and the host-window then does an iisreset.

It took me quite long to find out about this speciality with site-definition solution deployment and using the template afterwards when creating a site-collection.