Sideloading of apps is not enabled on this site

If you are deploying a solution/ sharepoint apps to sharepoint, at some point, you will likely come across this error: “sideloading of apps is not enabled on this site”.

so with this error, you won’t be able to deploy apps to sharepoint on-premise or online. to fix this issue, we have two different approaches for on-premise and online.

  1. on-premise server with full control

Enable-SPFeature e374875e-06b6-11e0-b0fa-57f5dfd72085 –url http://sp.contoso.com

2. sharepoint online

It is 2-steps solution for sharepoint online

  1. download and install sharepoint online management shell
  2. execute the script below
#CODE STARTS HERE
$programFiles = [environment]::getfolderpath("programfiles")
add-type -Path $programFiles'\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll'
Write-Host 'Ready to enable Sideloading'
$siteurl = Read-Host 'Site Url'
$username = Read-Host "User Name"
$password = Read-Host -AsSecureString 'Password'
 
$outfilepath = $siteurl -replace ':', '_' -replace '/', '_'
 
try
{
    [Microsoft.SharePoint.Client.ClientContext]$cc = New-Object Microsoft.SharePoint.Client.ClientContext($siteurl)
    [Microsoft.SharePoint.Client.SharePointOnlineCredentials]$spocreds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
    $cc.Credentials = $spocreds
    $site = $cc.Site;

    $sideLoadingGuid = new-object System.Guid "AE3A1339-61F5-4f8f-81A7-ABD2DA956A7D"
    $site.Features.Add($sideLoadingGuid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None);
     
    $cc.ExecuteQuery();
     
    Write-Host -ForegroundColor Green 'SideLoading feature enabled on site' $siteurl
    #Activate the Developer Site feature
}
catch
{ 
    Write-Host -ForegroundColor Red 'Error encountered when trying to enable SideLoading feature' $siteurl, ':' $Error[0].ToString();
}

#CODE ENDS HERE

Run the code as shown below, enter the site url with username nad password for your sharepoint online, the powershell will take care of the rest for you.

enable-sideloading-sharepoint-online_thumb

Advertisements

Download files as Zip File in SharePoint

Introduction

In this post we will see how to download selected document library items as zip file. The zip file creation api is from open source code of icsharpcode.net

Skill Level – Medium

Download files as Zip

When I am working on this requirement, I happened to check icharpcode.net which was very helpful with its api to create zip file.
The next step is to get the selected document library items and just call the api to create zip file. We need to provide one button in ribbon so that users can click it to save the zip file. In the button click we will have the code to read selected items and generate zip file.

The same logic I found in this site http://www.deviantpoint.com/post/2010/05/08/SharePoint-2010-Download-as-Zip-File-Custom-Ribbon-Action.aspx. But, download zip is not working for subsites and also to the sites that does not have managed path.

As many users are using that code, I am only modifying the code and maintain the credibility to Deviantpoint.com. The feature will still have the same name ‘DeviantPoint Download Zip Feature’ and the new code will be working for subsites and also for the sites that does not have managed path.

Following are the main methods to download as zip file, other code is just to create ribbon button and call these methods when button is clicked

using(MemoryStream ms = newMemoryStream())
{
    using(ZipFileBuilder builder = newZipFileBuilder(ms))
    {
        foreach(intid initemsIDs)
        {
            SPListItem item = library.GetItemById(id);
            if(item.IsFolder())
                AddFolder(builder, item.Folder, string.Empty);
            else
                AddFile(builder, item.File, string.Empty);
        }
        builder.Finish();
        WriteStreamToResponse(ms);
    }
}
privatestaticvoidAddFile(ZipFileBuilder builder, SPFile file, stringfolder)
{
    using(Stream fileStream = file.OpenBinaryStream())
    {
        builder.Add(folder + "\\"+ file.Name, fileStream);
        fileStream.Close();
    }
}
privatevoidAddFolder(ZipFileBuilder builder, SPFolder folder, stringparentFolder)
{
    stringfolderPath = parentFolder == string.Empty ? folder.Name : parentFolder + "\\"+folder.Name;
    builder.AddDirectory(folderPath);
    foreach(SPFile file infolder.Files)
    {
        AddFile(builder, file, folderPath);
    }
    foreach(SPFolder subFolder infolder.SubFolders)
    {
        AddFolder(builder, subFolder, folderPath);
    }
}
privatevoidWriteStreamToResponse(MemoryStream ms)
{
    if(ms.Length > 0)
    {
        stringfilename = DateTime.Now.ToFileTime().ToString() + ".zip";
        Response.Clear();
        Response.ClearHeaders();
        Response.ClearContent();
        Response.AddHeader("Content-Length", ms.Length.ToString());
        Response.AddHeader("Content-Disposition", "attachment; filename="+ filename);
        Response.ContentType = "application/octet-stream";
        byte[] buffer = newbyte[65536];
        ms.Position = 0;
        intnum;
        do
        {
            num = ms.Read(buffer, 0, buffer.Length);
            Response.OutputStream.Write(buffer, 0, num);
        }
        while(num > 0);
        Response.Flush();
    }
}

ZipFileBuilder is the class file that is created to call the Zip api and it is available in the source code
‘itemsIDs’ is the array of selected items of the document library that should be filled. When Download button is clicked, it is this array we fill.

If you do not want to use Zip file code to download, then write object model code to download files in the download button click event.

To summarize,

1) Download the code
2) Deploy the wsp ( Site collection level feature ‘DeviantPoint Download Zip Feature’ will be created)
3) Activate the sitecollection feature ‘DeviantPoint Download Zip Feature’
(Tip- siteurl/_layouts/ManageFeatures.aspx?Scope=Site will show you sitecollection features)
4) ‘Download as Zip’ button will be available in the ribbon to use

Sharepoint Webpart development with Customized ToolPart

To add customized Html content to the Toolpart panel, we need develop a Toolpart object, attach it to the webpart object.

the steps to add a toolpart object to a webpart:

1. Create a ToolPart object implement the Microsoft.SharePoint.WebPartPages.ToolPart

2. override the ApplyChanges method, save the values entered in the ToolPart panel to the webpart, calling this.ParentToolPane.SelectedWebPart can get the reference object to its webpart object

3. override the GetToolParts method in the webpart class, add the customized ToolPart object to the ToolPart list

Note: to retain the properties value defined in the webpart, the properties must be set to Personalizable attribute. PeralizationScope.Shared will make the variable visible to everybody, PeralizationScope.User will make the variable consistance and retained for the specific user.

Sharepoint CQWP CAML

using CAML in Content Query WebPart to refine the result is an effective way to customize the result. The use of DateTime is triky.

By Default, To get Today’s Date, you can call

<Value Type=”DateTime”><Today/></Value>

. the date result you get from this caml query doesn’t include the time. to include the time, add IncludeTimeValue=”True” to the Value open Tag.

<Value Type=”DateTime” IncludeTimeValue=”True”><Today/></Value>

The DateTime format used in SharePoint is ISO8601. To convert strand datetime format to the format which sharepoint can understand, call

 SPUtility.CreateISO8601DateTimeFromSystemDateTime(<DateTime>)

You can also retrieve the DateTime offset by days,

<Value Type=”DateTime”><Today OffsetDays=”-10″ /></Value> 

Add dll reference from GAC

To Add a dll reference to a project from GAC, you can’t use normal way to navigate to C:\Windows\assembly folder to select the dlls.

The actual path to the dlls in the GAC are C:\Windows\assembly\gac_msil\\_\.dll, however, before you can navigate to this path, you need run the following to make it visible to you.

type : “cd\windows\assembly”
type: “attrib -r -h -s desktop.ini”
type: “ren desktop.ini desktop.bak”

now you can open it and add reference.

To revert back to the original structure, run

Ren desktop.bak desktop.ini

It will revert back to original view