Category

Portals

FBA roles and SPRoleAssignment

By | SharePoint | No Comments

Still unable to set SPListItem permissions to FBA role in .Net Framework 3.5? Use the direct name of your FBA rule in claim form to make it working.

SPRoleDefinition spRole = elevatedWeb.RoleDefinitions["Read"];
SPRoleAssignment roleAssignment = new SPRoleAssignment("c:0-.f|roleprovidername|rolename", null, "rolename", null);
roleAssignment.RoleDefinitionBindings.Add(spRole);
Item.RoleAssignments.Add(roleAssignment);
Item.Update();

SharePoint: Replace hyperlink paths in CEWP by using Powershell

By | News, Portals, Powershell, SharePoint | No Comments

Upgrading portal or changing its domain name leaves old hyperlink paths in the Content Editor WebParts and there is no way to upgrade hyperlinks such as just only by changing Managed paths entries. Luckily, we modified a script written by Johnny Bouder (link here) according to update all hyperlink paths to correct format.

param([string]$url,[string]$oldpath,[string]$newpath)
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | out-null;
[System.Reflection.Assembly]::LoadWithPartialName("System.Xml");
 
function SP-Web-CleanCEWPContent ($w) {
$file = $w.GetFile("default.aspx");
if ($file.Exists) {
$webPartManager = $w.GetLimitedWebPartManager($file.Url,[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared);
$webParts = $webPartManager.WebParts;
foreach($webPart in $webParts) {
$checkString = "*" + $oldpath + "*";
if ($webPart.GetType() -eq [Microsoft.SharePoint.WebPartPages.ContentEditorWebPart] -and $webPart.Content.InnerText -like $checkString ) {
$oldElement = $webPart.Content;
$oldText = $webPart.Content.InnerText;
$xmlDoc = New-Object System.Xml.XmlDocument;
$xmlElement = $xmlDoc.CreateElement("MyElement");
$xmlElement.InnerText = $oldText.Replace($oldpath,$newpath);
$webPart.Content = $xmlElement;
$webPartManager.SaveChanges($webPart);
Write-Host -ForegroundColor Red "Updating web at "$w.Url;
}
}
}
}
function SP-ProcessSubwebs($ww) {
SP-Web-CleanCEWPContent($ww);
Write-Host("Processing web at " + $ww.Url);
if ($ww.Webs.Count -gt 0) {
foreach($sw in $ww.Webs) {
SP-ProcessSubwebs($sw);
}
}
}
$site = New-Object Microsoft.SharePoint.SPSite($url);
$web = $site.RootWeb;
SP-ProcessSubwebs($web);

Easy usage, just only type ./script.ps1 -url http://newPortalAddress -oldpath http://oldPortalAddress -newpath http://newPortalAddress .

SharePoint: Powershell Get-SPSite in WSS 3.0

By | Powershell, SharePoint | No Comments

This simple Powershell snipplet gets the SPSite site instance in Windows SharePoint Services 3.0. Script also traps the exception in case of non-existence of SharePoint
site located at $url.

function global:Get-SPSite([string]$url) {
$site = $null
trap [Exception] {
continue;
}
$site = new-object Microsoft.SharePoint.SPSite($url)
return $site
}

… and here is an implementation:

$site = Get-SPSite($URL)
if ($site) {
#your code
}
else {
Write-Host -ForegroundColor Red "ERROR: Site $URL has not been found"
}

c#: System.IO.FileNotFoundException in winforms

By | SharePoint, Winforms | No Comments

Have you faced to the FileNotFoundException error message in your WinForms SharePoint application despite the fact that you have all necessary permissions?

System.IO.FileNotFoundException: The Web application at http:// could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

Maybe you read this article
but the workaround actually does not work? What your winform app deals with app
settings? Nothing, the problem is somewhere else.

Solution: Try to check out winform‘s target platform and server’s platform. They
should be the same. The error occurs in the SPSite constructor, try to  switch to the same
target platform and to avoid the problem.