Friday, June 28, 2013

How to bypass Edit Properties Page or Skip EditForm.aspx Page while uploading documents in a document library

How to bypass Edit Properties Page while uploading documents in a document library(or)
Skip EditForm.aspx while uploading documents to document library in SharePoint 2010.

1.       Append this to the end of the URL for .aspx URL:   &ToolPaneView=2   and press Enter 

YourSiteName – Name of your Site DNS Name or Server Name
YourListName – Name of list or document library Name
YourFormName – Name of the form (page) name

2.  Click Add a Web Part and add a Content Editor Web Part

3.  Move the Content Editor Web Part below the list web part
Edit the web part and click the Source Editor button

Add the following...

<script type="text/javascript">
function GetQueryStringArgs()
{
    //fetch querystring and remove first ?
    var qs=(location.search.length>0?location.search.substring(1):"");
    //create an object for saving data
    var args={};
    var items=qs.split("&");
    var item=null,
        name=null,
        value=null;
    //add to args object one by one
    for(var i=0;i<items.length;i++)
   {
        item=items[i].split("=");
        name=decodeURIComponent(item [0]);
        value=decodeURIComponent(item[1]);
        args[name]=value ;
     }
        return args ;
    }
var args=GetQueryStringArgs();
var urlReferrer=document.referrer.toString ();
if(urlReferrer.indexOf("Upload")!=-1)
{
    window.frameElement.commitPopup();
}
</script>

Reference:

Monday, June 24, 2013

Programmatically delete all sub sites in a site collection(Sharepoint)


I have found one of the very useful code below to delete all sub sites in a site collection.


using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using Microsoft.SharePoint;  
using Microsoft.SharePoint.Security;  
 
 
namespace SiteDeletion  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Console.WriteLine("Executing program");  
 
            //Target site to delete sub sites from  
            string siteURL = "http://YourSiteURL/";  
 
            SPSecurity.RunWithElevatedPrivileges(delegate()  
            {  
                Console.WriteLine("Opening site");  
                using (SPSite oSite = new SPSite(siteURL))  
                {  
                    Console.WriteLine("Opening web");  
                    using (SPWeb osubWeb = oSite.OpenWeb())  
                    {  
                        Console.WriteLine("Getting sub sites");  
                        SPWebCollection subSites = osubWeb.GetSubwebsForCurrentUser();  
                        Console.WriteLine("looping");  
                        foreach (SPWeb subWeb in subSites)  
                        {  
                            //If you need to keep sites of a particular name  
                            if (subWeb.Title.Contains("Template"))  
                            {  
                                Console.WriteLine("NOT deleteing site: " + subWeb.Title);  
                            }  
                            else 
                            {  
                                Console.WriteLine("DELETING: " + subWeb.Title);  
                                DeleteWeb(subWeb);  
                            }  
                        }  
                    }  
 
 
 
                }  
            });  
 
            //Console.ReadLine();  
        }  
 
        public static void DeleteWeb(SPWeb web)  
        {  
            SPWebCollection subwebSites = web.GetSubwebsForCurrentUser();  
 
            if (subwebSites.Count > 0)  
            {  
                foreach (SPWeb w in subwebSites)  
                {  
                    DeleteWeb(w);  
                }  
            }  
 
            web.Delete();  
            return;  
        }  
 
    }  
}

Reference

http://simplisticsharepoint.blogspot.sg/2013/03/programmatically-delete-all-sites-in.html 

Programmatically changing the logo to Sharepoint all sites and subsites

I have found one of the very useful code below to change logo to Sharepoint all sites and subsites
using Console application. Happy coding. Cheers.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.IO;
namespace UpdateLogo
{
    class Program
    {
        static void Main(string[] args)
        {
            string site;
            string siteLogo;
            try
            {
                if (args.Length == 0)
                {
                    Console.WriteLine("Enter the Web Application URL:");
                    site = Console.ReadLine();
                    Console.WriteLine("Enter the Site Logo URL:");
                    siteLogo = Console.ReadLine();
                }
                else
                {
                    site = args[0];
                    siteLogo = args[1];
                }
                SPSite tmpRoot = new SPSite(site);
                SPSiteCollection tmpRootColl = tmpRoot.WebApplication.Sites;
                //Enumerate through each site
                foreach (SPSite tmpSite in tmpRootColl)
                {
                    //Enumerate through each web for the site
                    foreach (SPWeb tmpWeb in tmpSite.AllWebs)
                    {
                        //Update the logo for the current Web
                        tmpWeb.AllowUnsafeUpdates = true;
                        tmpWeb.SiteLogoUrl = siteLogo;
                        tmpWeb.Update();                                         
                        tmpWeb.AllowUnsafeUpdates = false;
                        //Log to a file, where the logo is applied!
                        StreamWriter SW;
                        SW = File.AppendText("C:\\LogoLog.txt");
                        SW.WriteLine(tmpWeb.Url);
                        SW.Close();
                        //Dispose of the Web Object
                        tmpWeb.Dispose();
                    }
                    //Dispose of the Site Object
                    tmpSite.Dispose();
                }
                //Dispose of the Root Site Object
                tmpRoot.Dispose();
                //Confirmation Message
                Console.WriteLine("The operation completed successfully");
            }
            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry("Logo Updater", ex.Message);
                //Failure Message
                Console.WriteLine("The operation failed");
            }
        }
    }
}

Programmatically applying themes to Sharepoint all sites and subsites


I have found one of the very useful code below to apply themes to Sharepoint all sites and subsites
using Console application. Enjoy coding. Cheers.


using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.IO;
namespace Theme_Update
{
    class Theme_Update
    {
        static void Main(string[] args)
        {
            string site;
            string siteTheme;
            try
            {
                if (args.Length == 0)
                {
                    Console.WriteLine("Enter the Web Application URL:");
                    site = Console.ReadLine();
                    Console.WriteLine("Enter the Site Theme:");
                    siteTheme = Console.ReadLine();
                }
                else
                {
                    site = args[0];
                    siteTheme = args[1];
                }
                SPSite tmpRoot = new SPSite(site);
                SPSiteCollection tmpRootColl = tmpRoot.WebApplication.Sites;
                //Enumerate through each site
                foreach (SPSite tmpSite in tmpRootColl)
                {
                    //Enumerate through each web for the site
                    foreach (SPWeb tmpWeb in tmpSite.AllWebs)
                    {
                            //Apply the default theme for the current Web
                            tmpWeb.AllowUnsafeUpdates = true;
                            tmpWeb.ApplyTheme("none");
                            tmpWeb.Update();
                            tmpWeb.ApplyTheme(siteTheme);
                            tmpWeb.Update();
                            tmpWeb.AllowUnsafeUpdates = false;

                        //Log to a file, where the theme is applied!
                            StreamWriter SW;
                            SW = File.AppendText("C:\\ThemeLog.txt");
                            SW.WriteLine(tmpWeb.Url);
                            SW.Close();

                            //Dispose of the Web Object
                            tmpWeb.Dispose();
                        }
                    //Dispose of the Site Object
                    tmpSite.Dispose();
                }
                //Dispose of the Root Site Object
                tmpRoot.Dispose();
                //Confirmation Message
                Console.WriteLine("The operation completed successfully");
            }
            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry("Theme Updater", ex.Message);
                //Failure Message
                Console.WriteLine("The operation failed");
            }
        }
    }
}

 

Create a Setup Project with desktop shortcut in a Visual studio 2008/2010/2012


 
Add a Setup Project to your Solution
·  1. Right click on your Solution and add a new project
·  2. Select Other Project Types >> Setup and Deployment >> Visual studio installer.
·  3. Add a name and Location to the project.
·  4. Click OK

Add item to Application Folder.
·  1. Right click on Application Folder>>ADD>>Project Output
·  2. Select the appropriate project
·  3. Select Primary Output on the selection area.
·  4. Click OK

Add item to User’s desktop Program Menu.
·  1. In the left pane of the Setup/File System window click on Application Folder.
·  2. Right click on the primary output/(active).
·  3. Select short cut to Primary output.
·  4. Drag the shortcut item to User’s desktop.
·  5. Repeat steps 1 to 3
·  6. Drag the shortcut item to User’s Program Menu.

Change the Desktop icon
·  1. Right click on the root folder (File system on Target machine).
        A drop down menu will popup.
·  2. Select custom folder on the bottom of the menu. and name as Icon.
·  3. Select an icon and copy that into the custom folder.
·  4. Open User's desk top folder under root and select the shortcut.
        Right click on the shortcut and go to properties window.
·  5. Go to properties Icon and select the icon on 'Icon' folder.
·  6. Select User's programme menu and repeat steps 4 and 5.

Build the Application and Install on a machine.

Reference