Export-SPWeb script to get backup all lists and libraries

Posted Yorum yapınSharePoint 2010, Sharepoint 2013 içinde yayınlandı

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:

[code language=”powershell”]
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
}
}
}
}
[/code]

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

Posted Yorum yapınSharepoint 2013, Windows Server 2012 R2 içinde yayınlandı

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

SharePoint 2013 REST API and Charset Problem

Posted Yorum yapınSharepoint 2013 içinde yayınlandı

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:

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

 

Hope it helps!

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

Posted 4 YorumSharepoint 2013 içinde yayınlandı

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

Get Yahoo Weather and Parse it in C#

Posted Yorum yapınSharepoint 2013, Yahoo içinde yayınlandı

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();

Limit NewsFeed to Display Latest 5 Posts in SharePoint 2013

Posted 5 YorumSharepoint 2013 içinde yayınlandı

I was having an issue to retrieve latest posts from newsfeed,lets say take 5 of them.Tried everything,but newsfeed webpart didnt support filtering according to my need.

So i tried a “css-trick” code i found over the internet and improved it to my needs:

function get5posts() {
$(".ms-microfeed-seeMoreThreadsDivContainer").hide();
var limit = 5;
$("#ms-feedthreadsdiv .ms-microfeed-thread").each(function (i) {
if (i >= limit) {
$(this).addClass("ms-hide");
}
});
}

The code above shows only 5 posts on page load.But what happens if you add more in newsfeed? The 5 item limit exceeds and you need to call a function to restrict it to 5 item:

Call get5posts() in page load event:

$(document).ready(function (e) {
get5posts();
});

Afterwards call it again if user clicks on post reply button:

$("#ms-postbutton").on("click", function () {
get5posts();
});

This will limit NewsFeed to 5 posts only.

Nice Trick!

Considerations after Backup & Restore in SharePoint

Posted Yorum yapınSharepoint 2013 içinde yayınlandı

These are what i experienced on some of the projects i have worked on:

1) Scripts,Styles,Fonts,Layouts needs to be published.Because they stay as draft items in your “_catalogs/masterpage”

2) The lists that use filtering needs to be updated.Sometimes it bugs out.

3) If you have used NewsFeed in your portal,its contents need to be deleted from MicroFeed special list.Just click on the guid item and it will show the users posts.This is important because people will see users’ posts from the test environment

4) Never ever use SPContext.Current.Web.List(“blabla”) to access lists.Its one of the evil reasons your users getting permission problems.

5) If you have used database connections in your code,update your web.config.Backup&Restore doesnt backup your web.config

6) Always backup the live server through powershell script in case something goes wrong and you may need to restore later.

Will update this post as i see fit in the future.

Get Attachments using SPServices in SharePoint 2013

Posted 5 YorumSharepoint 2013 içinde yayınlandı

[sourcecode language=”javascript”]

$().SPServices({

operation: "GetListItems",
async: false,
listName: "listname",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
$().SPServices({
operation:’GetAttachmentCollection’,
listName: "listname",
ID: $(this).attr("ows_ID"),
completefunc: function (xData, Status) {
$(xData.responseXML).find("Attachments").each(function() {
alert($(this).text());
});
}

});
});
}
});[/sourcecode]

But theres a much more better way to do it,Thanks to Marc:

[sourcecode language=”javascript”]
var p = $().SPServices({
operation: "GetListItems",
listName: "listname",
CAMLQueryOptions: "<QueryOptions>" +
"<IncludeAttachmentUrls>TRUE</IncludeAttachmentUrls>" +
"</QueryOptions>"
});

p.done(function() {

$(p.responseXML).).SPFilterNode("z:row").each(function() {

var attachments = [];

var att = $(this).attr("ows_Attachments");
if(att !== "0") {
attachments = att.split(";#"); // Now you’ll have an array of attachment URLs
} else {
// att will be "0", indicating that there are no attachments
}

});

});
[/sourcecode]

Have fun 🙂