Solved – You do not have permission to open this Web site in SharePoint Designer 2013


Recently we had installed SharePoint designer 2013, and while trying to open a SharePoint online web site.

However we were getting the below error.

“403 FORBIDDEN403 FORBIDDEN403 FORBIDDEN403 FORBIDDEN403 FORBIDDEN”

Installing the SharePoint designer SP 1 (64 bit in our case) https://www.microsoft.com/en-in/download/details.aspx?id=42009 fixed the issue.

Hope it helps..

Fixed – Exception calling “CreateSPNavigationNode” with “4” argument(s): Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) in SharePoint 2013


Got this error while running a PowerShell script that creates Navigation in the portal.

Adding the logged in user as to Site Collection Administrator group fixed the issue.

http://alstechtips.blogspot.in/2014/07/sharepoint-2013-access-is-denied.html

Hope it helps..

Fixed – An unrecoverable error has occurred. Please contact your system administrator error while uploading the profile picture in SharePoint 2013


Hi ,

got the below error while trying to upload profile picture for the user.

The reason was because no My Site was configured.

http://thuansoldier.net/?p=2326

Creating a My Site site collection and specifying it as My Site Host location fixed the issue.

Profile picture getting updated.

Hope it helps..

Fixed – “There was a problem retrieving data for this field. Updating values in this field is disabled temporarily. You can still update values in the other fields” error in User Profile Service application in SharePoint 2013


Got this error while trying to edit user profile

There was no Managed Metadata Service Application configured.

http://social.technet.microsoft.com/wiki/contents/articles/25537.there-was-a-problem-retrieving-data-for-this-field-updating-values-in-the-field-is-disabled-temporarily-you-can-still-update-values-in-other-fields.aspx

Configuring it as mentioned in the post fixed the issue

Hope it helps..

Fixed: The request message is too big. The server does not allow messages larger than 2097152 bytes while uploading attachment using CSOM in SharePoint 2013


Got below error while uploading document to SharePoint folder.

Following PowerShell script can be used to increase the limit.

$ws = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$ws.ClientRequestServiceSettings.MaxReceivedMessageSize = 5242880
$ws.ClientRequestServiceSettings.MaxParseMessageSize  = 5242880
$ws.Update()

https://msdn.microsoft.com/en-us/library/office/ff599489%28v=office.14%29.aspx

Hope it helps !

The file or folder name contains characters that are not permitted SharePoint 2013. Removing the invalid characters using Regex C#.


Was getting the below error while uploading attachment to SharePoint document library.


string pattern = "[\\~#%&*{}/:<>?|\"-]";
string replacement = " ";

Regex regEx = new Regex(pattern);

string sanitized = Regex.Replace(regEx.Replace(input, replacement), @"\s+", " ");

Helpful post

http://simplyaprogrammer.com/2008/05/importing-files-into-sharepoint.html

Hope it helps

Code to upload multiple attachments to SharePoint Folder using Client Object Model



public static void UploadDocument(
string siteURL,
string documentListName,
string documentListURL,
string documentName,
byte[] documentStream,
string folderName,
string invoiceId)
{
using (var clientContext = new ClientContext(siteURL))
{
// Get Document List
var documentsList = clientContext.Web.Lists.GetByTitle(documentListName);

// check if folder already exists else create folder

if (!FolderExists(clientContext.Web, documentListName, folderName))
{
var info = new ListItemCreationInformation();
info.UnderlyingObjectType = FileSystemObjectType.Folder;
info.LeafName = folderName.Trim();
var newItem = documentsList.AddItem(info);
newItem["Title"] = folderName;
newItem.Update();
clientContext.ExecuteQuery();
}

var fileCreationInformation = new FileCreationInformation();

// Assign to content byte[] i.e. documentStream
fileCreationInformation.Content = documentStream;

// Allow owerwrite of document
fileCreationInformation.Overwrite = true;

// Upload URL
fileCreationInformation.Url = siteURL + documentListURL + folderName + "/" + documentName;
var uploadFile = documentsList.RootFolder.Files.Add(fileCreationInformation);

// Update the metadata for a field having name "DocType"
uploadFile.ListItemAllFields["Invoice_x0020_Id"] = invoiceId;

uploadFile.ListItemAllFields.Update();
clientContext.ExecuteQuery();
}
}


public static bool FolderExists(Web web, string listTitle, string folderUrl)
{
var list = web.Lists.GetByTitle(listTitle);
var folders = list.GetItems(CamlQuery.CreateAllFoldersQuery());
web.Context.Load(list.RootFolder);
web.Context.Load(folders);
web.Context.ExecuteQuery();
var folderRelativeUrl = string.Format("/{0}/{1}", list.RootFolder.Name, folderUrl);
return Enumerable.Any(folders, folderItem => (string)folderItem["FileRef"] == folderRelativeUrl);
}

Remove web part that is causing error from a SharePoint page


Hi,

On adding a web part if in a page at times it throws error and we need to access the page and remove that web part.

To do so we need to add the following querystring to the page url

http://localhost/Pages/Home.aspx?contents=1

It will open the page and will present the list of web parts in the page from wherein we can select and delete the web part that was causing the error.

Hope it helps..

CAML Query Builder for SharePoint 2013


Hi,

Recently had to write CSOM code to fetch value of a particular list item.

The following tool made it really easy to write the CAML Query.

https://spcamlqueryhelper.codeplex.com/

Bye..

Use IsDateEmpty property of SharePoint DateTime Control to check for null


We were using SharePoint:DateTimeControl
in one of our Application Pages in SharePoint. The control returns current date time for SelectedDate if no date is selected.

To check for this we can use IsDateEmpty property.

Hide “Page-“ from title of SharePoint Page


To hide the “Page -“text from the page title

Open the BlankWebPartPage.aspx in the page designer and remove the tag highlighted in green.

http://stackoverflow.com/questions/13303764/page-layouts-not-available-in-sharepoint-designer

However, sometimes the Page Layouts link is missing. This is a common scenario:

•you have a subsite in a site collection

•the publishing feature is activated in the subsite, but not in the site collection

•you want to edit/add page layouts on the site collection level, to be used within your subsite

•when you open the site collection in SharePoint Designer, you can’t see Page Layouts in the Site Objects panel You now have 2 options: you can either activate the publishing feature in the site collection (and the Page Layouts link comes back), or you can use the All Files link and browse to the master pages and page layouts library (_catalogs > masterpage.) Either option will do, unless you really don’t want the publishing feature in the site collection

 

Hiding new item, edit, view selector from List View Web Part in SharePoint 2013


We had a requirement to hide the new item button, edit button etc. from a List View Web Part.

 

The way we achieved it was using a Content Editor Web Part and pointing it to Jscript File with the following CSS,

By finding the following id(s) and setting display as none.

List View with hidden controls.

Cannot retrieve the URL specified in the Content Link property. For more assistance, contact your site administrator error in SharePoint.


We were getting this error in one of our pages in SharePoint.

Just verify the Content Link it might not be pointing to correct url in the Content Editor Web Part.

Hope it helps..

Check if a user is a SharePoint Administrator in JavaScript – SharePoint 2013.


Hi,

Had a requirement to check if user is a SharePoint Admin or not and accordingly hide few elements in the page. We used the below code in our custom master page

Sample Code


var currentUser;

function IsUserAdmin() {
clientContext = SP.ClientContext.get_current();
spWeb = clientContext.get_web();
currentUser = spWeb.get_currentUser();
clientContext.load(currentUser);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded(sender, args) {

var isUserAdmin = currentUser.get_isSiteAdmin();
if (isUserAdmin) {

alert('Current User is Administrator');

} else {

alert('Current User is not an Administrator');
}
}

function onQueryFailed(sender, args) {

alert('Request failed. ' + args.get_message() +
'\n' + args.get_stackTrace());
}

ExecuteOrDelayUntilScriptLoaded(GetCount, "sp.js");

Hope it helps ..

Sample PowerShell script to create web application and a site collection in SharePoint 2013


Just sharing a sample script that we are using to create a web application and a site collection of type publishing in it.

 

# SharePoint cmdlets
Add-PsSnapin Microsoft.SharePoint.PowerShell</pre>
# Set variables
$WebAppName = "MyAppPool"
$WebAppHostHeader = "servername"
$WebAppPort = "portnumber"
$url = "http://servername"
$WebAppAppPool = "MyAppPool"
# This User has to be a Sharepoint Manager Account
$WebAppAppPoolAccount = "domain\username"
$AuthenticationMethod = "NTLM"
$ap = New-SPAuthenticationProvider -UseWindowsIntegratedAuthentication -DisableKerberos

# Create a new Sharepoint WebApplication
New-SPWebApplication -Name $WebAppName -Port $WebAppPort -HostHeader $WebAppHostHeader -URL $url -ApplicationPool $WebAppAppPool -ApplicationPoolAccount (Get-SPManagedAccount $WebAppAppPoolAccount) -AuthenticationMethod $AuthenticationMethod -AuthenticationProvider $ap

# Set variables
$SiteCollectionName = "MySiteCollection"
$SiteCollectionURL = "http://servername:portnumber/"
$SiteCollectionTemplate = "BDR#0"
$SiteCollectionLanguage = 1033
$SiteCollectionOwner = "LSS\lssspadmin"

# Create a new Sharepoint Site Collection
New-SPSite -URL $SiteCollectionURL -OwnerAlias $SiteCollectionOwner -Language $SiteCollectionLanguage -Template $SiteCollectionTemplate -Name $SiteCollectionName

Hope it helps ..

Use TryGetList to check if a list exist in SharePoint (SharePoint Object Model)


Hi,

We were getting the following error that “list doesn’t exist in the site” because the user was not having read permission on that list.

The code we were using was

SPList myList= spWeb.Lists[“mylist”];

A better approach would be

SPList myList = spWeb.Lists.TryGetList(“myList”);

If(myList != null )

// …

Bye ..

Fixed – Error creating web application in SharePoint 2013.


Hi,

We were facing issues while creating a new web application through central administration. The user was the farm administrator.

The way we got it fixed was by increasing the set the values for the properties in the Central Admin Sites’ App Pool

Followed by an IISRESET

Hope it helps ..

Using clientidmode property to get the id of the control in JavaScript in Visual Web Part


Hi,

In a Visual Web Part we were saving few values in a hidden input field and were retrieving it in the jScript. However the issue we were facing was the id of the control kept changing.

http://therightstuff.de/2006/02/14/Accessing-Controls-In-SharePoint-Web-Parts-Using-JavaScript-On-The-Client-Side.aspx

Here the clientidmode property came to rescue.

<input id=”hiddenobject” type=”hidden” clientidmode=”Static” runat=”server”/>

With the clientidmode set as static the id remains the same.

Hope it helps.

A web part or web form control on this Page cannot be displayed or imported. The type could not be found or it is registered as safe error in while deploying visual web part in SharePoint 2013.


Got this error while adding web part to one of the pages in SharePoint. It was all working fine earlier.

 

After much struggle, realized that the LiveVewWebPart.webpart had the incorrect namespace specified.

Correcting it resolved the issue.

Upload User Profile Picture programmatically in SharePoint 2013


Hi,

We recently had a requirement to create a web part that would be used to update user profile picture and few other properties.

For this we used the FIileUpload control.

The code used


public void UploadPhoto(string accountName, byte[] image)
 {

string loginNameForProfile = accountName.Substring(accountName.IndexOf(@"|") + 1);

if (profileUpload.HasFile)
 {
 SPSecurity.RunWithElevatedPrivileges(delegate()
 {
 using (SPSite site = new SPSite(SPContext.Current.Site.Url))
 {
 SPServiceContext serviceContext = SPServiceContext.GetContext(site);
 UserProfileManager userProfileMgr = new UserProfileManager(serviceContext);
 ProfilePropertyManager profilePropMgr =
 new UserProfileConfigManager(serviceContext).ProfilePropertyManager;

// Retrieve all properties for the "UserProfile" profile subtype,
 // and retrieve the property values for a specific user.
 ProfileSubtypePropertyManager subtypePropMgr =
 profilePropMgr.GetProfileSubtypeProperties("UserProfile");
 UserProfile userProfile = userProfileMgr.GetUserProfile(loginNameForProfile);

 SPSite mySite = new SPSite(userProfileMgr.MySiteHostUrl);
 SPWeb web = mySite.RootWeb;
 SPFolder subfolderForPictures = web.Folders["User Photos"].SubFolders["Profile Pictures"];

web.AllowUnsafeUpdates = true;

Stream fs = profileUpload.PostedFile.InputStream;

byte[] buffer = new byte[profileUpload.PostedFile.ContentLength];
 fs.Read(buffer, 0, Convert.ToInt32(profileUpload.PostedFile.ContentLength));
 fs.Close();
 int largeThumbnailSize = 300;
 int mediumThumbnailSize = 72;
 int smallThumbnailSize = 48;

&nbsp;

string accName = accountName.Substring(accountName.IndexOf(@"\") + 1);
 using (MemoryStream stream = new MemoryStream(buffer))
 {
 using (Bitmap bitmap = new Bitmap(stream, true))
 {

 CreateThumbnail(bitmap, largeThumbnailSize, largeThumbnailSize, subfolderForPictures,
 accName + "_LThumb.jpg");
 CreateThumbnail(bitmap, mediumThumbnailSize, mediumThumbnailSize, subfolderForPictures,
 accName + "_MThumb.jpg");
 CreateThumbnail(bitmap, smallThumbnailSize, smallThumbnailSize, subfolderForPictures,
 accName + "_SThumb.jpg");
 }
 }
 string pictureUrl = String.Format("{0}/{1}/{2}_MThumb.jpg", subfolderForPictures.ParentWeb.Site.Url, subfolderForPictures.Url, accName);
 // Change the value of a single-value user property.
 userProfile[PropertyConstants.PictureUrl].Value = pictureUrl;
 imgUserProfile.ImageUrl = pictureUrl;
 // Save the changes to the server.
 userProfile.Commit();

web.AllowUnsafeUpdates = false;
 }
 });

}
 }

public SPFile CreateThumbnail(Bitmap original, int idealWidth, int idealHeight, SPFolder folder, string fileName)
 {
 SPFile file = null;

Assembly userProfilesAssembly = typeof(UserProfile).Assembly;

Type userProfilePhotosType = userProfilesAssembly.GetType("Microsoft.Office.Server.UserProfiles.UserProfilePhotos");
 MethodInfo[] mi_methods = userProfilePhotosType.GetMethods(BindingFlags.NonPublic | BindingFlags.Static);

MethodInfo mi_CreateThumbnail = mi_methods[0];
 if (mi_CreateThumbnail != null)
 {
 file = (SPFile)mi_CreateThumbnail.Invoke(null, new object[] { original, idealWidth, idealHeight, folder, fileName, null });
 }

return file;
 } // end of function

The helpful post

http://lixuan0125.wordpress.com/2013/04/08/upload-user-profile-pictures-programmatically-sharepoint-2013/

Hope it helps

Cannot make a call on this channel because a call to Open() is in progress error in CRM 2011.


Hi,

We had developed a Visual Web Part for SharePoint 2013 that used IOrganizationService of CRM 2011. It was all working fine however yesterday it started throwing this error.

After some investigation we realized that the user whose credentials we were using as Client Credentials for the OrganizationService had recently been changed.

Updating it to the correct updated one fixed the issue for us.

Hope it helps.

Disable wsstracing.exe in SharePoint


Hi,

At times we need to disable wsstracing.exe to improve the system’s performance at it uses too much CPU resources.

Open Command Prompt as Administrator

To Disable

  • sc stop “SPTraceV4”
  • sc config “SPTraceV4” start= disabled

To Delete

  • sc delete “SPTraceV4”

bye.

Hide “Personalize this Page” option in SharePoint for all the users.


Hi,

We recently had a requirement to hide the Personalize this Page option from the SharePoint Site for all the users.

The way we can do it is by commenting out the following element in the Welcome.ascx page

(\15\TEMPLATE\CONTROLTEMPLATES\Welcome.ascx)

The other option through central administration

http://donalconlon.wordpress.com/2011/04/28/hide-personalize-this-page-option-for-sharepoint-site/

Hope it helps.

Set SelectedDate for DateTimeControl in SharePoint.


While working on a visual web part wherein we were using SharePoint’s DateTimeControl, realized that it was not that straight forward to set the value for the DateTimeControl.

The following post came handy

http://blog.enderspsyche.com/2013/04/setting-datetimecontrol-date-in.html

Hope it helps!

Using JavaScript in custom master page for SharePoint 2013 that uses SP.js.


Hi,

We recently had a requirement to show no of listitems on a particular list on every page within the site. So we decided to use the JavaScript that does so in our custom master page itself.

This is how we got it working

Adding the SharePoint script link that refers to the SP.js file in our custom html master page.

<!–MS:<SharePoint:ScriptLink ID=”ScriptLink21″ Name=”sp.js” runat=”server” OnDemand=”false” LoadAfterUI=”true” Localizable=”false”>–>
<!–ME:</SharePoint:ScriptLink>–>

And then executing our script using the following method i.e. after SP.js is loaded

function GetCount() {

// code that uses CSOM to get the count

}


ExecuteOrDelayUntilScriptLoaded(GetCount, “sp.js”);

Hope it helps.

Object reference not set to an instance of an object. at Microsoft.SharePoint.Publishing.Internal.CodeBehind.AreaNavigationSettingsPage.OKButton_Click(Object sender, EventArgs e) error in AreaNavigationSettings.aspx page


Hi,

Was getting the above issue while trying to configure navigation for the SharePoint Site. Tried out different solutions mentioned in the following post.

http://phinotworking.com/stubborn-site-navigation-menu-items/

Corrected the JavaScript issue on the page, renamed the id of the div to something else instead of container but that didn’t work. Then through PowerShell script deleted few of the navigation links and again gave it a try. This time it worked properly.


I think the navigation page would have got corrupted or something because of those links and hence deleting those links fixed the issue.

Hope it helps.


Windows could not connect to the User Profile Service service \ Desktop is not available\ The dependency service or group failed to start errors in Windows Server 2008


Hi,

I was getting the above error after logging into the Windows Server 2008 machine. Tried out different things but nothing helped.

Finally we figured out the reason for this. Actually someone had configured the User Profile Service to run under a different credentials instead of Local System.

Running it back under the Local System account resolved the issue for us.

Hope it helps.