Tuesday 2 February 2016

Move Your file to Catalogs folder

Console for migration to sp2013 (move master page)


using Microsoft.SharePoint;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Movemp
{
    class Program
    {
        static void Main(string[] args)
        {
            String fileToUpload = @"C:\YourFile.txt";
            String sharePointSite = "http://*******:7778/_catalogs/masterpage";  // Change your site url
         
            SPSecurity.RunWithElevatedPrivileges(delegate()
                {
            using (SPSite oSite = new SPSite(sharePointSite))
            {
                using (SPWeb oWeb = oSite.OpenWeb())
                {
                    if (!System.IO.File.Exists(fileToUpload))
                        throw new FileNotFoundException("File not found.", fileToUpload);

                    SPFolder mPageFolder = oWeb.Folders["_catalogs"].SubFolders["masterpage"];
                    using (FileStream mPageStream = new FileStream(fileToUpload, FileMode.Open))
                    {
                        SPFileCollection mPageFileCollection = mPageFolder.Files;
                        SPFile mPageFile = mPageFileCollection.Add(
                            "YourFile.txt",  
                            mPageStream,true
                        );   // Change your file name
                    }
                }
               
            }
                });
        }
    }
}