Sharepoint 2013

SharePoint 2013 REST API and Charset Problem

tarihinde 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!

Sharepoint 2013

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

tarihinde 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

Sharepoint 2013

Get Yahoo Weather and Parse it in C#

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

SharePoint 2010

SharePoint 2010 Deployment Problem: Error occurred in deployment step ‘Retract Solution’

tarihinde yayınlandı

Today while i was working on a SharePoint 2010 project,i came across this problem:

“Error occurred in deployment step ‘Retract Solution’: C:\Windows\Temp\{some guid with packagename}.wsp could not be created because the contents could not be found under id {some guid} in the configuration database.

I was trying to figure out what the problem might be then i realized it was my fault :))

I stopped SharePoint 2010 Timer service before deploying.So starting the Timer Service from services.msc resolved my problem.

Sharepoint 2013

Limit NewsFeed to Display Latest 5 Posts in SharePoint 2013

tarihinde 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!

Sharepoint 2013

Considerations after Backup & Restore in SharePoint

tarihinde 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.

Sharepoint 2013

Get Attachments using SPServices in SharePoint 2013

tarihinde 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 🙂

Sharepoint 2013

Embedding UserControls to HTML page created by Design Manager

tarihinde yayınlandı

The design crash after you embed 2 or more User Controls in a html file.I have been figuring out a way to solve that problem today.

You can register User Controls using this statement:

[sourcecode language=”csharp”]
<!–SPM:<%@Register TagPrefix="UC" TagName="SampleUC" src="~/_controltemplates/SampleIntranet/SampleUC.ascx"%>–>
[/sourcecode]

Normally you can use;

[sourcecode language=”csharp”]
<!–MS:{UserControl registration}–>
[/sourcecode]

but when you add 2 user controls same way,design crashes.So you need to close the MS statement using “ME”.

Here’s how you can do it:

[sourcecode language=”csharp”]
<!–MS:<UC:SampleUC runat="server" id="SampleUCID">–>;
<!–ME:</UC:SampleUC>–>;
<!–MS:<UC:SampleUC2 runat="server" id="SampleUCID2">–>
<!–ME:</UC:SampleUC2>–>
[/sourcecode]

Hope that fix helps you

Sharepoint 2013

Problem & Solution: This solution contains no resources scoped for a Web application…

tarihinde yayınlandı

When i tried to deploy a webpart to a webapplication using both PS and Central Administration,i got the following warning:

This solution contains no resources scoped for a Web application and cannot be deployed to a particular Web application.

It tried to deploy it to GAC which i didnt want.Because it needs to be deployed to a WebApplication in my farm

Solution is;
Started Visual Studio and the project,opened Package.Template.xml in an editor and edited the line in yellow:
sorun

DeploymentTarget property needs to be set as “WebApplication”.Even though i changed it via project properties,it kept changing to GACDeployment so i had to edit Package xml.Just to be sure.

After deployment i got to choose the webapplication where i want it deployed.

Hope it helps