Friday, October 26, 2012

Failure decompressing data from a cabinet file - Error When Save Site as Template

Received an error "Failure decompressing data from a cabinet file" when trying to save a site as template. This is a known issue with no solution – occurs when we save site as a template with lot of content. KB: http://support.microsoft.com/kb/960969 .
If you receive this error after increasing the list/site template maximum size, Make sure its below 500 MB. (By default, the maximum size of the list or site template is set to 10 MB!), Typically 50 MB should be ideal.

stsadm -o setproperty -propertyname max-template-document-size -propertyvalue 50000000

There is a hard limit of List/Site template size of 500MB. So set the value less than 524288000 or you will get an error when saving the list as a template!

As per the above KB, You may receive error even your site template size is lesser than the conigured value! So what other options left to us? Export/Import!

In an another case, I open the site in SharePoint Designer, and deleted unused document templates from _cts folder, tried saving it again, it worked!

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Managed Paths Can't be use in List/Library/Sub-Site Names

We can not use Managed paths in SharePoint List or Library. E.g. "Sites" is a built-in Managed path. So you can't name any list/library/sub-sites as "Sites". This behavior is in SharePoint 2010 only and Not in MOSS 2007. 
"sites" cannot be used as a site name.

But you can use the managed paths in your Site collections. E.g. http://sharepoint.company.com/sites/sites


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, October 22, 2012

Pick the right w3wp.exe to attach among Multiple Worker processes while debugging

When multiple web applications running with multiple application pools, they will create multiple worker processes (W3WP.exe). While debugging code from Visual studio, we got pick the one belongs to the target web application, otherwise, debugger will not stop on break-points!

Don't forget to select "Show processes from all users", otherwise w3wp won't be showing up in attach process window!
attach w3wp process visual studio 2010
attach w3wp process visual studio 2010

How to select the correct W3WP.exe to attach?
If you use different user accounts for different application pools, you can just pick the right one easily by checking "User Name" column.

Follow these instructions to find the right worker process to attach:
  • From the running processes, we'll have to get the process id value. Lets go to Windows Task Manager >> View >> Select Columns (You'll see multiple w3wp.exe in task manager)
multiple w3wp.exe task manager 
  • Select the "PID (Process Identifier)" column from the list.multiple w3wp.exe instances Task Manager Find ID
  • Now go to command prompt, go to the directory "C:\windows\System32\Inetsrv"
  • Enter "Appcmd list wp"
This will list all running worker processes and their associated web applications. Now open the Task Manager to match the PID with the desired web application's worker process ID.
attach w3wp.exe process visual studio
Now you have the right w3wp process to attach!

Here I have my custom code deployed in the web application "SharePoint80 " and wanted to debug the same. So the W3WP process I've to attach is 2372.

Happy debugging!

For windows 2003 - IIS 6:
If you are running IIS 6 in windows 2003, You can get the list of worker processes with their associated web applications by running the vb script: iisapp.vbs located at: c:\windows\system32 folder.

You can type cscript iisapp.vbs in command line. If it says "Error - No Results" - Either your IIS sites are in Stopped state or no worker processes running.!

Alternatively, You can use Process Explorer from Microsoft to get the right worker process. Make sure you are selecting "Command Line" column in view to get the process with its associated web application.


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, October 21, 2012

Create Folders and Sub-Folders in SharePoint Programmatically

How to create Folders in SharePoint 2013:
To create a folder in SharePoint list or Library, follow these steps:
  • Navigate to your SharePoint list or library
  • From the "Files" tab on the Ribbon, Click on "New Folder" buttonsharepoint 2013 create a folder
  • Give a name to your new folder and click "Save" sharepoint 2013 create folder
What if you don't find "New Folder" button in the ribbon? 
If you don't get "New Folder" button, it could be disabled. Here is how to enable folders in SharePoint list:
  • Go to List Settings, Click on "Advanced Settings"
  • Scroll down and set "Yes" to Make "New Folder" command available option.sharepoint 2010 create folder in a list
In a Migration automation tool development, had to create folders and sub-folders from the code
programmatically. Here I'm sharing the code snippets in C# and in PowerShell.
  
      using (SPSite site = new SPSite("http://sharepoint.company.com"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    //Get the List
                    SPList list = web.Lists["Project Tracker"];

                    //Create a Folder
                    SPListItem folder = list.AddItem(list.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, "Sales Documents");
                    folder.Update();

                    //Create a Sub-Folder
                    SPListItem SubFolder = list.AddItem(folder.Folder.ServerRelativeUrl , SPFileSystemObjectType.Folder, "APAC Sales Docs");
                    SubFolder.Update();       

                 }         
             }
Alternatively, you can use:
 
                    //Get the List
                    SPList list = web.Lists["Shared Documents"];
                    String url = list.RootFolder.ServerRelativeUrl.ToString();
                    SPFolderCollection folders = web.GetFolder(url).SubFolders;

                    //Create new folder
                    folders.Add("New Documents");


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Friday, October 19, 2012

Get SPWeb Object from the URL

PowerShell Snap-in for SharePoint 2010 offers Get-SPWeb cmdlet to get SPWeb Object directly from the given web URL. But when writing .Net code in C# (or in PowerShell with MOSS 2007) SharePoint object model doesn't offer this mechanism.

However there is a Trick to get SPWeb Object from given URL: Get the SPWeb by calling SPSite.OpenWeb() Method.

Get SPWeb from Given URL: C# Code:

Using(SPSite site=new spsite(URL))
{
using(SpWeb web=site.openweb())
 {
   //Do something 
 }
} 

Same way, With MOSS 2007 PowerShell:

$webURL="http://sharepoint.compnay.com/sites/sales/us" #Subsite
$site = New-Object Microsoft.SharePoint.SPSite($WebURL) 
$web= $site.OpenWeb()


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, October 14, 2012

Cannot open database 'WSS_Content' Requested by the login. The login failed.

In a SharePoint 2007 environment, All of a sudden, all custom applications which uses server object model, started failing with an error: Cannot open Database WSS_Content_SharePoint_DB requested by the login. The login Failed. Login failed for user <domain\user_account>
Cannot open Database Database_Name requested by the login. The login Failed. Login failed for user <domain\user_account>
  
Root cause of the Problem: There was an old unused site collection's content database attached with the web application. Since the particular site collection was no longer needed, SharePoint Administrator just deleted the database during a maintenance window from SQL Server.

But SharePoint configuration was still referring the database and trying to connect! This error got logged multiple times in event log also. So the right sequence would be:
  • Delete the content database from SharePoint first (stsadm -o deletecontentdb or using Central Administration) 
  • Then delete the database from SQL Server.stsadm -o deletecontentdb
This error may appear when there is a permission issue and can be resolved by either granting access to the service account or changing the SharePoint Timer service's identity to the account which has enough privileges on the databases, which is described here: Event ID 3351: SQL database login failed

Cannot open database 'db_name' Requested by the login.- Error in SharePoint 2013:
Same issue happened in SharePoint 201, with Event ID: 3760

SQL Database "db_name" on SQL Server instance "sql_instance_name" not found. Additional error information from SQL Server is included below.

  Cannot open database “db_name” requested by the login. The login failed. Login failed for user ‘domain\login’
.

Solution: Remove the deleted Database reference from SharePoint using PowerShell:
Get-SPDatabase | where {$_.name -eq 'db_name'} | foreach {$_.Delete()};


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Saturday, October 13, 2012

Server error in '/' Application - The Resource cannot be found - Solution

In a SharePoint 2007 environment, called for fixing a issue: All SharePoint sites appeared with an error"SharePoint server error in '/' Application The Resource cannot be found. "

Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.


Requested Url: /sites/marketing/default.aspx

I know this is a really common error, usually this error occurs when some resources like Master pages, User controls, etc referenced by SharePoint site doesn't exist (or got deleted!). In this case, client applied a master page via custom WSP Solution, and the code deleted master page with out changing it to default master page.
Server error in '/' Application - The Resource cannot be found - SolutionSites reported "File Not Found" Error initially. After enabling stack trace and disabled custom error message in web.config file, all SharePoint sites appeared with an error"SharePoint server error in '/' Application The Resource cannot be found. "

All Application pages were accessible since they use different master page. All content pages were failing because the master page referenced by them got deleted!

Went to the view source of the page, Analyzed and found it is referencing to a master page "crescent.master" that doesn't exists!

To fix the issue: Tried setting a different master page via SharePoint designer, Error disappeared!

But we can't open each and every site and set master page, isn't it? Automation? PowerShell! Here is the PowerShell script to Reset master pages to "Default.master" for all sites of a site collection.

#Set-ExecutionPolicy RemoteSigned

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null

#For SharePoint 2007
function global:Get-SPSite($url){
    return new-Object Microsoft.SharePoint.SPSite($url)
}
 
#Get the site collection
Write-Host "Enter the Site Collection URL:"
$SiteCollURL= Read-Host
$SPSite = Get-SPSite($SiteCollURL)

    # Change Master Page for all webs
       foreach($SPweb in $SPSite.AllWebs)
        {
      $SPWeb.MasterUrl="/_catalogs/masterpage/default.master"
   $SPWeb.CustomMasterUrl = "/_catalogs/masterpage/default.master"
          $SPWeb.AlternateCssUrl = ""
   $SPWeb.Update()
   
        }


Other Causes & Solutions:
This error may occur when you edit page layouts in SharePoint designer( SPD converts the URL path that start with: "~/site/page/file.aspx" to "site/page/file.aspx")

Solution: Reset the master page! Just go to "http://YOUR-SITE/_Layouts/ChangeSiteMasterPage.aspx" page and change the master page to default.master.

Sometimes, IIS may the culprit. Check these settings in IIS:
  • This may happen when there is a Port conflict in IIS. Stop any other sites running on the same port. 
  • IIS configurations like Web Site's Home Directory path change could cause this issue. Make sure the Home directory exists (Its case sensitive, by the way!)
  • Make sure there is no conflict between Virtual Directory folder and your site (They both can't be in same name)


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Inline Editing in SharePoint 2010 - How to Enable? Not working? Set the Style to Default

Inline Editing feature in SharePoint 2010 provides us an option for editing items in the same page - Same Line, with out going to a separate edit form.

How to enable inline editing SharePoint 2010
Its configured in View's settings. To activate inline editing in SharePoint 2010, Just modify the view of the relevant List or Library.
inline editing sharepoint 2010
and enable the check-box for "Allow Inline Editing".
enable inline editing sharepoint 2010
Once enabled, You will get an Edit icon when you hover over list items.
how to enable inline editing sharepoint 2010
Remember, you can't edit the read-only fields (such as ID, calculated columns, Read only Fields - Created by, Modified, etc) in Inline editing.
sharepoint 2010 inline editing read only column
On clicking edit icon, you will get edit options for all editable controls of the item.
inline editing sharepoint 2010 list

Once done with your edit, you can either save or cancel editing by clicking on relevant button.

Inline Editing Doesn't Work in even after you enable the "Allow Inline Editing" check-box?
Inline editing only works, when you setup the view style to "Default". If you change it to any other style (say: Shaded, Newsletter, Boxed, etc) inline editing will not work!
inline editing sharepoint 2010 not workingMake sure, Your View's Style is: Default!


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, October 11, 2012

SharePoint Designer "Error Reading File" - Bulk Blank Lines Fix

Getting "Error Reading File" when trying to open a page in SharePoint Designer? Well, its a bug! SharePoint designer inserts Blank lines in the aspx file when you edit!!

Fix:
Open the page as text in SPD (or any other Text editor), Remove Blank Lines (Careful! Don't delete the code. Delete only blank lines). You can select few blank rows, and use Find & Replace!
Error Reading File
Here is the screenshot:
sharepoint designer inserting blank lines

Find the blank lines SharePoint designer adds, Remove Empty rows from the file.
sharepoint designer adding blank lines

There is a utility in codeplex: http://sharepointfilerepair.codeplex.com/


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, October 2, 2012

Find All Sites and Lists with Unique Permissions

Requirement is to Get the report of SharePoint 2010 (or 2007) Sites and Lists where Permission Inheritance is broken.

PowerShell script to Generate report for Unique Permissions:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

 #Get All Web Applications
$webApps = Get-SPWebApplication #"http://sharepoint.company.com"

#Write Header to CSV File 
"Site/List `t Title `t URL" | out-file UniquePermissions.csv

foreach ($webApp in $webApps)
{
    foreach ($site in $webApp.Sites)
    {
       foreach ($web in $site.AllWebs)
        {
   if ( ($web.HasUniqueRoleAssignments) -and ($web.IsRootWeb -eq $false))
   {
      $result ="Site `t $($web.Title) `t $($web.Url)"
      $result | Out-File UniquePermissions.csv -Append 
      #You can get the permissions applied by: $web.permissions | format-list member, basepermissions
   }
    foreach ($list in $web.Lists)
     {
     if (($list.HasUniqueRoleAssignments) -and ($list.Hidden -eq $false))
      {
        $result= "List `t $($list.Title) `t $($list.Url)" 
        $result | Out-File UniquePermissions.csv -Append 
      }
    }
    $web.Dispose()
  }
   $site.Dispose()
 }

}
       
and the Output file in Excel:
sharepoint find unique permissions


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, October 1, 2012

Bulk Upload Files to SharePoint using PowerShell

Requirement is to upload multiple files from a local folder to SharePoint document library along with its Metadata.

Bulk upload can be done via SharePoint interface by selecting multiple file upload, however setting metadata may be an issue, when it comes to large number of documents.

PowerShell script to Bulk Upload Files to SharePoint Library:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Function to Upload File
function UploadAllFilesFromDir($WebURL, $DocLibName, $FolderPath)
{
 #Get the Web & Lists to upload the file
 $site = New-Object Microsoft.SharePoint.SPSite($WebURL)
 $web= $site.OpenWeb()
      
#Get the Target Document Library to upload
$List = $Web.GetFolder($DocLibName)
 
#Get the Files from Local Folder
$Files = Get-ChildItem $FolderPath #You can filter files by: -filter “*.pdf” 

#upload the files
foreach ($File in $Files)
{
    #Get the Contents of the file to FileStream 
    $stream = (Get-Item $file.FullName).OpenRead()
    
    # Set Metadata Hashtable For the file - OPTIONAL
    $Metadata = @{"Country" = "United States"; "Domain" = "Sales"}
    
    #upload the file              
    $uploaded = $List.Files.Add($File.Name, $stream,$Metadata, $TRUE)
    
    #dispose FileStream Object
    $stream.Dispose()
}
 
#Dispose the site object
$site.Dispose()
}
  
#call the upload function
UploadAllFilesFromDir "http://SharePoint.crescent.com/sites/sales/" "Shared Documents" "c:\Documents\"

Upload Files from CSV and apply Metadata in Bulk: 
Here is my CSV file with list of file names and metadata.

PowerShell to upload and apply metadata in bulk:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

#Configuration Variables
$SiteURL="https://sharepoint.crescent.com/sites/sales/"
$LibraryName="Team Docs"
$FilesPath="d:\FilesToUpload\"
$CSVFilePath="d:\UploadData.csv"

#Get the Web
$Web = Get-SPWeb $SiteURL
#Get the Target Document Library to upload
$Library = $Web.GetFolder($LibraryName)

#Get CSV file contents
$CSVData = Import-CSV -path $CSVFilePath

#Iterate through each Row in the CSV
Foreach ($Row in $CSVData)
{
    write-host "Uploading File:"$Row.FileName

    #Get the File from local disk 
    $SourcePath= Join-Path $FilesPath -ChildPath $Row.FileName
    $SourceFile = (Get-ChildItem $SourcePath).OpenRead()

    #Set Metadata Hashtable For the file
    $Metadata = @{"Country" = $Row.Country; "Department" = $Row.Department}

    #upload the file              
    $uploaded = $Library.Files.Add($Row.FileName, $SourceFile, $Metadata, $TRUE)
}




You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


You might also like:

Related Posts Plugin for WordPress, Blogger...