Posted in SharePoint 2010, Sharepoint 2013

Export-SPWeb script to get backup all lists and libraries

Wrote this Powershell script according to my company’s needs,but you can fork and use it if you like

Export-SPWeb Script to get backup of all lists/libraries in a site collection.

But I’ll also share it here:

Add-PSSnapin Microsoft.Sharepoint.Powershell

$site = Get-SPSite
$path = "C:\Backup2015\ListBackups"
$serverurlpath =""
$listurlpath=""
$listurlwithoutformat=""
$dosyapath =""
$itemURLNEW=""

foreach($web in $site.AllWebs){
    $serverurlpath=$web.Url
    $serverlistsurlpath=$web.ServerRelativeUrl -replace "/","\"
    $serverurlport = ([System.Uri]$serverurlpath).Port
    $serverurlhost = ([System.Uri]$serverurlpath).Host.Split('.-') -join "_"   

    if($serverurlport -eq "80")
    {
     if(!(Test-Path -Path ($path + "\" + $serverurlport)))
     {
      New-Item -Path ($path + "\" + $serverurlport) -Type Directory
     }    

     if(!(Test-Path -Path (($path + "\" + $serverurlport + "\" + $serverurlhost))))
     {
       New-Item -Path ($path + "\" + $serverurlport + "\" + $serverurlhost) -Type Directory
     }

     foreach($list in $web.lists)
     {      

        If (!(Test-Path ($path + "\" + $serverurlport + "\" + $serverurlhost + $serverlistsurlpath))) {
              New-Item -Path ($path + "\" + $serverurlport + "\" + $serverurlhost + $serverlistsurlpath) -Type Directory
        }            

        $itemURLNEW= "$($list.RootFolder.ServerRelativeUrl)"
        if($serverlistsurlpath -eq "\")
        {
          $dosyapath = "$path\$($serverurlport)\$($serverurlhost)$($serverlistsurlpath)$($list -replace "/","\").cmp"
        }

        else
        {
          $dosyapath = "$path\$($serverurlport)\$($serverurlhost)$($serverlistsurlpath)\$($list-replace "/","\").cmp"
        }   

        if(!(Test-Path ($dosyapath)) -and $list.Hidden -eq $false)
        {
           export-spweb $web.URL -ItemUrl $itemURLNEW -IncludeUserSecurity -IncludeVersions All -path "$dosyapath" -nologfile
        }
     }
    }   

    if($serverurlport -eq "1111")
    {
     if(!(Test-Path -Path ($path + "\" + $serverurlport)))
     {
      New-Item -Path ($path + "\" + $serverurlport) -Type Directory
     }    

     if(!(Test-Path -Path (($path + "\" + $serverurlport + "\" + $serverurlhost))))
     {
       New-Item -Path ($path + "\" + $serverurlport + "\" + $serverurlhost) -Type Directory
     }

     foreach($list in $web.lists)
     {   

        If (!(Test-Path ($path + "\" + $serverurlport + "\" + $serverurlhost + $serverlistsurlpath))) {
              New-Item -Path ($path + "\" + $serverurlport + "\" + $serverurlhost + $serverlistsurlpath) -Type Directory
        }            

        $itemURLNEW= "$($list.RootFolder.ServerRelativeUrl)" 

        if($serverlistsurlpath -eq "\")
        {
           $dosyapath = "$path\$($serverurlport)\$($serverurlhost)$($serverlistsurlpath)$($list -replace "/","\").cmp"
        }

        else
        {
           $dosyapath = "$path\$($serverurlport)\$($serverurlhost)$($serverlistsurlpath)\$($list -replace "/","\").cmp"
        }       

        if(!(Test-Path ($dosyapath)) -and $list.Hidden -eq $false)
        {
           export-spweb $web.URL -ItemUrl $itemURLNEW -IncludeUserSecurity -IncludeVersions All -path "$dosyapath" -nologfile
        }
     }
    }
}
Posted in Sharepoint 2013, Windows Server 2012 R2

Solution of “Application Server Role, Web Server (IIS) Role: configuration error”

For some reason SharePoint 2013’s prerequisite msi cant find which server manager to use and fails installation of Prerequisite files.

So you need to go Windows/System32, find servermanager.exe ,duplicate it and then rename it to servermanagercmd.exe

After this,re-run prerequisite installer,it will work.

Capture4

If it doesn’t,you haven’t enabled downloading setup files remotely in mmc(group policy editor) settings.

To do this;
1-You need to add “GP Editor” Snapin in MMC.
2-Go to Computer Configuration->Administrative Templates-> System
2-Update “Specify settings for optional…” policy as Enabled
3-Update “Contact Windows Update…” as selected
4-Click Apply

Posted in Sharepoint 2013

SharePoint 2013 REST API and Charset Problem

I’ve been on a project lately.The project was to migrate contents from a farm to another.Since there was corporate rules like a bank we couldnt use Content Migration tool in CA so our only option was to use SharePoint REST API.

Whenever i sent values from a list in farm to another list in another farm,i had problems with non-english chars.

For example; characters like “İ”,”Ç”,”Ğ” arent ASCII supported so my only option was to use “Encoding”

There are a couple known drawbacks while using Encoding with HttpWebRequest so i implemented those too in my code below:

Encoding utf8NoBom = new UTF8Encoding(false);
Byte[] itemPostData = utf8NoBom.GetBytes(itemPostBody);
var datak = utf8NoBom.GetString(itemPostData);
itemRequest.ContentLength = utf8NoBom.GetByteCount(datak);
itemRequest.MaximumResponseHeadersLength = -1;

 

Hope it helps!

Posted in Sharepoint 2013

Problem and Solution : Dynamic operations can only be performed in homogenous AppDomain.

If u have ever used “dynamic” keyword in your webpart code,its 100% possibility you will meet this error.

Its because using dynamic operation in same appdomain as sharepoint is not supported in new LegacyCASModel.

So heres a workaround i did to make it work:

if you wrote a timerjob, edit owstimer.config otherwise edit web.config:

Instead of this:
<trust level=”Full” originUrl=”” legacyCasModel=”true” />

Use this:
<trust level=”Full”  />

and add this to <configuration><runtime>:
<NetFx40_LegacySecurityPolicy enabled=”false”/>

Hope it helps

Posted in Sharepoint 2013, Yahoo

Get Yahoo Weather and Parse it in C#

Here’s a code i wrote for a sharepoint 2013 visual webpart which retrieves Istanbul’s temperature and condition text from Yahoo Weather (YQL) in JSON format and parsing.


string results = "";
using (WebClient wc = new WebClient())
{
results = wc.DownloadString("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%3D2344116&format=json");
}

dynamic jo = JObject.Parse(results);
var items = jo.query.results.channel.item.condition;
var code = items.code;
var temp = items.temp;
var text = items.text;

Console.WriteLine(code + " - " + temp + " - " + text);

Console.Read();