kwizcom banner advertisement

Upload File to SharePoint Library using PowerShell

July 31, 2012    , , ,
We had a PowerShell script code to generate Large Lists reports in D:\Reports, and now want to periodically upload them to a document library "Reports" in my Admin site. So, scheduled a PowerShell script to do so. Here is my PowerShell code to upload the report to a document library. Upload file to SharePoint 2010 Library using PowerShell Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #Function to Upload File function UploadFile($WebURL, $DocLibName, $FilePath) { #Get the Web & Lists to upload the file $Web = Get-SPWeb $WebURL $List = $Web.GetFolder($DocLibName) #Get the Files collection $Files = $List.Files #Get File Name from Path $FileName = $FilePath.Substring($FilePath.LastIndexOf("\")+1) #delete the File from library, if already exist! if($Files.Item($DocLibName +"/" + $FileName)) { $Files.delete($DocLibName +"/" + $FileName) } #Get the File $File= Get-ChildItem $FilePath #Add File to the colle
Upload File to SharePoint Library using PowerShell Upload File to SharePoint Library using PowerShell Reviewed by Salaudeen Rajack on July 31, 2012 Rating: 5

Delete or Restore SharePoint Recycle Bin Items based on Deleted Date using PowerShell

July 30, 2012    , ,
Requirement is to Restore all the Items deleted before last week from Recycle bin, which were already deleted from End-User Recycle bin (1st Stage Recycle bin). Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue $WebApp=get-spwebapplication "http://sharePoint.crescent.com" foreach ($SPSite in $WebApp.Sites) { #Contains both First Stage & Second Stage Recycle bin Items $SPRecycleBinItemCollection = $SPSite.RecycleBin; #write-host "Processing Site: " $SPSite.RootWeb.Title "`n" #write-host "Total No. of Items in Recycle bin: " $SPRecycleBinItemCollection.Count for ($i=$SPRecycleBinItemCollection.Count-1; $i -GE 0; $i--) { # check whether the Recycle bin Item is a SecondStageRecycleBin Item if($SPRecycleBinItemCollection[$i].ItemState -eq [Microsoft.SharePoint.SPRecycleBinItemState]::SecondStageRecycleBin) {
Delete or Restore SharePoint Recycle Bin Items based on Deleted Date using PowerShell Delete or Restore SharePoint Recycle Bin Items based on Deleted Date using PowerShell Reviewed by Salaudeen Rajack on July 30, 2012 Rating: 5

Display Lists from Other Site Collection/Web Application Using JQuery

July 29, 2012    , ,
Another frequent requirement is to display Lists/Libraries from Root site to Sub-site or Sub-site to Root site, and in some cases from Cross Site collection. While this can be fulfilled by Web Services, Custom Web Parts, etc, here is the simple JQuery method to display SharePoint list from another site collection or from different site. I deployed the JQuery file to my WFEs and referred it in the script: <script type="text/javascript" src="/_layouts/jquery/jquery.min.js"></script> <!-- placeholder for processing Image and List View --> <div id="ListViewPlaceHolder"><img src="/_layouts/images/GEARS_AN.GIF" alt="" /></div> <script type="text/javascript"> <!-- Specify the View URL of the list you want to show: --> var ShowWP = "https://portal.crescent.com/clients/mcdonald/Lists/ClientNotes/AllItems.aspx"; $("#ListViewPlaceHolder").load(ShowWP +" #Web
Display Lists from Other Site Collection/Web Application Using JQuery Display Lists from Other Site Collection/Web Application Using JQuery Reviewed by Salaudeen Rajack on July 29, 2012 Rating: 5

Maintenance Page for SharePoint - Quick way to Implement

July 26, 2012    , , , , , ,
Here is the quick way to implement Maintenance page in SharePoint, during scheduled down times/upgrade/service pack patching: Create a new app_offline.htm file in IIS Root folder of your SharePoint site. Place some descriptive text/images to the file, Make sure the file size is at least 512 bytes (otherwise, you will get 404 page not found error!). That's all! I've placed the maintenance page content like this: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Site Under Maintenance</title> </head> <body> <div align="center"><br /> <br /> <br /> <br /> <img src="http://testIntranet.crescent.com/images/maintenance.gif" width="600" height="300" /></div> </body> </html> and the output: Maintenance page for SharePoint 2010/
Maintenance Page for SharePoint - Quick way to Implement Maintenance Page for SharePoint - Quick way to Implement Reviewed by Salaudeen Rajack on July 26, 2012 Rating: 5

How to Create - Update - Delete SharePoint Views Programmatically?

July 23, 2012    , , , ,
Often in development we may have to deal with SharePoint Views programmatically. Here I'm sharing the code snippets from my recent project to handle views programmatically. Creating a New View Programmatically: using (SPSite site = new SPSite("http://crescent.sharepoint.com")) { using (SPWeb web = site.OpenWeb()) { //Get the List SPList ProjectDocuments = web.Lists["Client Documents"]; //Set the View fields StringCollection ViewFields = new StringCollection(); ViewFields.Add("Type"); ViewFields.Add("Name"); //Set the View Filter and Sort order string viewQuery = @" <Where><Eq><FieldRef Name='Status' /><Value Type='Choice'>In Progress</Value></Eq></Where><OrderBy><FieldRef Name='Modified'
How to Create - Update - Delete SharePoint Views Programmatically? How to Create - Update - Delete SharePoint Views Programmatically? Reviewed by Salaudeen Rajack on July 23, 2012 Rating: 5

SharePoint 2010 Custom Error Page Redirect in Event Receivers

July 21, 2012    , ,
In my last post Allow only Certain File Types to be Uploaded in SharePoint Document Library using Event Receiver I developed an Event receiver to prevent files other than PDF from being uploaded to a document library. So when user tries to upload a file other than PDF they'll get an Error message in the window saying "You are allowed to upload only PDF files". No issues! But in most of the cases, user tried uploading word files, receives the error message and complains they don't know how to make the word or other file types to PDF. So, to help out users, what we wanted to do is instead of just saying "You are allowed to upload only PDF files", what if we instruct users on "How to convert the word document to PDF" with some descriptive text? Sounds good! Lets get started! Do these 3 modifications to the existing project to get SharePoint event receiver custom error page. SharePoint redirect from event receiver : 1. Update the Event Receiver:
SharePoint 2010 Custom Error Page Redirect in Event Receivers SharePoint 2010 Custom Error Page Redirect in Event Receivers Reviewed by Salaudeen Rajack on July 21, 2012 Rating: 5

Restrict File Types in SharePoint Document Library Upload using Event Receiver

July 19, 2012    , , ,
Requirement: In a Project collaboration SharePoint site, had a requirement to Allow users to upload only PDF files to a Document library and prevent all other files from being uploaded. Solution: Our requirement is basically to prevent files being uploaded other than PDF, isn't it? So lets jump to visual studio and create a Event Receiver in SharePoint to restrict file types in SharePoint document library. How to Create a Event Receiver in SharePoint 2010? Compared with MOSS 2007, Creating Event receivers in SharePoint 2010 is very easy With Visual Studio 2010. Here are the steps: 1. Create a New Visual Studio Project, Choose SharePoint >> 2010 >> Event Receiver >> Give it a Name. Say " Crescent.ProjectSites.AllowPDFOnly " 2. Make it as a Farm solution, choose the event receiver properties as in the below screen. 3. On clicking "Finish" button, Visual Studio will create the project structure as: 4. Now, in the Elements.xm
Restrict File Types in SharePoint Document Library Upload using Event Receiver Restrict File Types in SharePoint Document Library Upload using Event Receiver Reviewed by Salaudeen Rajack on July 19, 2012 Rating: 5

SharePoint 2013 Preview Officially Launched!

July 18, 2012    ,
SharePoint 2013 preview officially launched with great features. Here are some useful URL's to get started: SharePoint 2013 Home: http://technet.microsoft.com/en-us/sharepoint/fp142366 Download SharePoint 2013 Preview: http://technet.microsoft.com/en-us/evalcenter/hh973397 SharePoint 2013 system requirements: http://technet.microsoft.com/en-us/library/cc262485%28office.15%29.aspx SharePoint 2013 Developer Training: http://msdn.microsoft.com/en-US/office/apps/fp123626 SharePoint 2013 IT PRO Training: http://technet.microsoft.com/en-US/sharepoint/fp123606 New Features, Getting Started, Overview, etc. http://msdn.microsoft.com/en-us/library/jj162979%28office.15%29.aspx http://technet.microsoft.com/en-us/sharepoint/fp142374   SharePoint 2013 Preview discontinued features: http://officepreview.microsoft.com/en-us/sharepoint-server-help/discontinued-features-and-modified-functionality-in-microsoft-sharepoint-2013-preview-HA102892827.aspx SharePoint Designer 2013: http://www.
SharePoint 2013 Preview Officially Launched! SharePoint 2013 Preview Officially Launched! Reviewed by Salaudeen Rajack on July 18, 2012 Rating: 5

Customize Top Navigation Programmatically in SharePoint 2010

July 12, 2012    , , , , ,
Requirement: Had to customize the Top navigation with bunch of provided internal/external links as part of a branding project. Solution: Designed a feature to programmatically add links to top navigation bar. when activated, feature will add bunch of links to the top navigation bar. Customize navigation programmatically in SharePoint 2010: public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSite site = properties.Feature.Parent as SPSite; SPWeb rootWeb = site.RootWeb; // Get the top link bar. SPNavigationNodeCollection topNavNodes = rootWeb.Navigation.TopNavigationBar; // Create a simple external Link node. SPNavigationNode node = new SPNavigationNode("I-Best", "http://ibest.crescent.com",true); topNavNodes.AddAsLast(node); //Add Heading & child Links node SPNavigationNode oNewNode = new SPNavigationNode(&quo
Customize Top Navigation Programmatically in SharePoint 2010 Customize Top Navigation Programmatically in SharePoint 2010 Reviewed by Salaudeen Rajack on July 12, 2012 Rating: 5

SharePoint List Column Limits

July 08, 2012    , , ,
There are limits in number of columns we can create in a SharePoint list. You may Get "Column Limit Exceeded" when You add a new column to a SharePoint List. This is because of the column limitations. For SharePoint 2003/2007: With Windows SharePoint Services, you can create the following numbers of each column type for each list or library:     64 Single line of text and Choice (drop-down menu or radio buttons)     31 Multiple lines of text and Choice (check boxes (allow multiple sections))     32 Number and currency     32 Hyperlink     16 Date and time     16 Lookup     16 Yes/No     8 Calculated Refer this KB for the limitations on the maximum number of columns we can have: http://support.microsoft.com/kb/823555 The above applies to SharePoint 2007 as well, but This is not a hard limit. For SharePoint 2010 lists Column limits:   Refer this Technet article: http://technet.microsoft.com/en-us/library/cc262787.aspx#Column
SharePoint List Column Limits SharePoint List Column Limits Reviewed by Salaudeen Rajack on July 08, 2012 Rating: 5

How to Create SharePoint List or Library Programmatically?

July 07, 2012    , , ,
At times, We may have to create List or Document Libraries programmatically. These code snippets will help to get it done. Using .Net Object Model (C#) using (SPSite site = new SPSite("http://sharepoint")) { using (SPWeb web = site.OpenWeb()) { //Create a document library web.Lists.Add("Project Docs", "Library for Storing Project Documents", SPListTemplateType.DocumentLibrary); //Create a Link List web.Lists.Add("Portal Links", "Links to Portal Resources", SPListTemplateType.Links); //SPListTemplateType.Links can be: SPListTemplate AssetTemplate = web.ListTemplates["Links"]; //Create a List based on Custom List template SPListTemplateCollection CustomListTemplates = site.GetCustomListTemplates(web); SPListTem
How to Create SharePoint List or Library Programmatically? How to Create SharePoint List or Library Programmatically? Reviewed by Salaudeen Rajack on July 07, 2012 Rating: 5

Activate-Deactivate Features Programmatically in SharePoint

July 06, 2012    , , ,
At times, We may have to activate/deactivate features programmatically. Here is the code snippet: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; namespace ActivateFeature { class Program { static void Main(string[] args) { string SiteURL; if (args.Length == 0) { Console.WriteLine("Enter the site collection URL:"); SiteURL = Console.ReadLine(); } else { SiteURL = args[0]; } SPSite oSPSite = new SPSite(SiteURL); //Get the Feature to Activate SPFarm farm = oSPSite.WebApplication.Farm; SPFeatureDefinitionCollection features = farm.FeatureDefinitions; SPFeatureDefinition feature = features[new Guid("05BA4E54-C1E9-4244-8276-06451EBBB260")];
Activate-Deactivate Features Programmatically in SharePoint Activate-Deactivate Features Programmatically in SharePoint Reviewed by Salaudeen Rajack on July 06, 2012 Rating: 5

Set Sorting, Filter, Group By in SharePoint Views Programmatically

July 04, 2012    , , , ,
SharePoint List views uses CAML internally to Filter, Sort list items. In a Recent project, we had to programmatically set the Filter and Sort order of default views. How to Get the CAML? Simple! use U2U CAML Query builder, one of my favorite SharePoint tool. C# code to set the View Filter, Sort options: //Get the List, say "Project Tasks" SPList ProjectTasks = web.Lists["Project Tasks"]; //Get the view SPView ProjectTasksView = ProjectTasks.DefaultView; // Or you can get a specific view by: List.Views["View-Name"] //Set the CAML Query string viewQuery = @" <Where><Eq><FieldRef Name='Status' /><Value Type='Choice'>In Progress</Value></Eq></Where><OrderBy><FieldRef Name='Modified' Ascending='False' /></OrderBy> "; //Update the view ProjectTasksView.Query = viewQuery; ProjectTasksView.Update(); //Update the List ProjectTasks.
Set Sorting, Filter, Group By in SharePoint Views Programmatically Set Sorting, Filter, Group By in SharePoint Views Programmatically Reviewed by Salaudeen Rajack on July 04, 2012 Rating: 5

How to Create Custom Application Page in SharePoint 2010 to get List Owners?

July 02, 2012    , , , ,
In my environment, This is one of a Frequently asked question: How do I find who has created a List or Library? oops, I don't find any direct way from SharePoint interface to know who has created a List or Library. Lets develop a Application page, host it under Layouts folder and let the users access that page to get the list owners information. How to get Who has Created a List/Library? Here is how to Create a Custom Application Page for SharePoint 2010 using Visual Studio - Step by Step: 1. Create a Visual studio "Empty SharePoint Project", Give it a name, Lets say "ListOwner". 2. Add a New Item to the Project, choose "Application Page", Name it, Say " ListOwner.aspx " 3. This will create the project structure as in the below screen. 4. Now, Lets add a grid to the page, to display all the Lists and its owners from the current site. Go to the ListOwner.aspx page, locate the code block: <asp:Content ID="
How to Create Custom Application Page in SharePoint 2010 to get List Owners? How to Create Custom Application Page in SharePoint 2010 to get List Owners? Reviewed by Salaudeen Rajack on July 02, 2012 Rating: 5

Run a Console Application and Mail Output Report with PowerShell

July 01, 2012    , ,
We had a console application GetStorageReport which runs and generates detailed storage reports based on some SharePoint APIs. Got the requirement to run the tool periodically and mail the output report of the application. Scheduled a PowerShell script to execute the application and mail the report to Administration team. Here is my PowerShell code:   Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #Trigger the executable file Start-Process "D:\Scripts\StorageReport\GetStorageReport.exe" # Wait until the report is generated while(-not (Test-Path "D:\Scripts\StorageReport\StorageReport.csv")) { Start-Sleep 30 #sleep for 30 seconds } $ReportDate=get-date -Format "MMM-dd-yyyy" #Rename the Report Rename-Item -Path "D:\Scripts\StorageReport\StorageReport.csv" -NewName "D:\Scripts\StorageReport\StorageReport_$ReportDate.csv" #Send the Mail $MailMessageParameters = @{ SmtpSe
Run a Console Application and Mail Output Report with PowerShell Run a Console Application and Mail Output Report with PowerShell Reviewed by Salaudeen Rajack on July 01, 2012 Rating: 5

Set ListViewWebPart Toolbar Type Programmatically

July 01, 2012    , ,
While adding a ListViewWebPart to web part page programmatically, had to set the List View's tool bar to "Summary View". After trying for hours found this code: //Method to Set the Tool bar type public static void SetToolbarType(SPView spView, String toolBarType) { spView.GetType().InvokeMember("EnsureFullBlownXmlDocument", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.InvokeMethod, null, spView, null, System.Globalization.CultureInfo.CurrentCulture); System.Reflection.PropertyInfo nodeProp = spView.GetType().GetProperty("Node", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); XmlNode node = nodeProp.GetValue(spView, null) as XmlNode; XmlNode toolbarNode = node.SelectSingleNode("Toolbar"); if (toolbarNode != null) { toolbarNode.A
Set ListViewWebPart Toolbar Type Programmatically Set ListViewWebPart Toolbar Type Programmatically Reviewed by Salaudeen Rajack on July 01, 2012 Rating: 5

How to Change Site Collection URL in SharePoint?

July 01, 2012    , , , , , , ,
How to change SharePoint site URL? At times, we get requests to change the Site collection URLs. While its relatively straightforward and easy by going to Site Actions >> Site Settings >> Title, description, and icon under Look and Feel to change the sub-site's URL, changing the site collection URL is not so! You can Change the URL of SharePoint 2010 Sub-Site using PowerShell also: Get-SPWeb http://sharepoint.com/sites/sitecollection/subsite | Set-SPWeb -RelativeUrl newsubsiteURL How to Change Site Collection URL in SharePoint? To change the site collection's URL, There is no out-of-the-box user interface or direct ways. So, after making sure the destination URL's managed path is already in place and verifying the target site collection URL doesn't exist, I do this three step manual process. Backup the Source Site collection Delete the Source Site collection (Yes, its must! we've to delete the site collection before restoring it. Otherwi
How to Change Site Collection URL in SharePoint? How to Change Site Collection URL in SharePoint? Reviewed by Salaudeen Rajack on July 01, 2012 Rating: 5
Powered by Blogger.