Friday, 22 April 2016

Increase Max Length Of Multiple People Picker Control






Sometimes you got warning message like "Item cannot be more than 256 characters" at the people editor control while adding or updating large number of data. To avoid this just add below script to content editor web part & Change g_MAX_LEN value as required.


<script language="ecmascript" type="text/ecmascript">
function onPageLoad() {
  g_MAX_LEN = 2000;
}
$(document).ready(onPageLoad);
</script>

Thanks & Regards
Modi Vishal

Tuesday, 5 April 2016

SharePoint 2010 Shortcuts

http://<Site>/_vti_bin/Lists.asmx: - List Web Service
http://<Site>/_layouts/viewlsts.aspx:- View All Site Contents
http://<Site>/Page.aspx?contents=1:- View Web part For Current Page 

Wednesday, 16 September 2015

Event Receivers BeforeProperties and AfterProperties

SharePoint 2010 Create Monthly Timer Job Which Execut On Last Day Of Month

      
 MonthlyTJService is helper class in which your logic for timer job is implemented



       string MonthlyTJ = "Monthly TJ";

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
                 SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPSite site = properties.Feature.Parent as SPSite;
                    DeleteJob(site);
                    CreateJob(site);
                });
          
         }

        private static void DeleteJob(SPSite site)
        {
            foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
            {
                 job.Delete();
            }
        }

        private static void CreateJob(SPSite site)
        {
            if (site == null)
                throw new ArgumentNullException("site", "site is null.");
          
            MonthlyTJService monthlyTJ = new MonthlyTJService(MonthlyTJ, site.WebApplication);
            SPMonthlySchedule monthlyTJSchedule = new SPMonthlySchedule()
            {
                BeginDay = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month),
                EndDay = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month),
                BeginHour = 23,
                BeginMinute = 15,
                EndHour = 23,
                EndMinute = 45
            };

            monthlyTJ.Schedule = monthlyTJSchedule;
            monthlyTJ.Properties.Add("siteurl", site.Url);
            monthlyTJ.Update();
       }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            DeleteJob(properties.Feature.Parent as SPSite); // Delete the Job
        }

SharePoint 2010 CAML Query For Search Within Folder

Search For Non Lookup Field Value

   <Query>
       <Where>
           <Eq>
               <FieldRef Name='Title'/>
               <Value Type='Text'>Val</Value>
           </Eq>
       </Where>
   <Query>
   <QueryOptions>
       <ViewAttributes Scope='Recursive' />
   </QueryOptions>



Search For Lookup Field Value 

   <Query>
       <Where>
           <Eq>
               <FieldRef Name='Title' LookupId='True'/>
               <Value Type='Lookup'>Val</Value>
           </Eq>
       </Where>
   <Query>
   <QueryOptions>
       <ViewAttributes Scope='Recursive' />
   </QueryOptions>

Thursday, 12 September 2013

Create treeview structure of document library and its item using client object model

private void FillTreeView()
        {
            documentLibraryStructureTreeView.Nodes.Clear();

            ClientContext clientContext = new ClientContext("http://sp2013:10021/demo");
            clientContext.Credentials = new System.Net.NetworkCredential("username", "password", "servername");
            clientContext.Load(clientContext.Web.Lists);
            clientContext.ExecuteQuery();
            foreach (List list in clientContext.Web.Lists)
            {
                try
                {

                    if (list.BaseType.ToString() == "DocumentLibrary" && !list.IsApplicationList && !list.Hidden && list.Title != "Form Templates" && list.Title != "Customized Reports" && list.Title != "Site Collection Documents" && list.Title != "Site Collection Images" && list.Title != "Images" && list.Title != "Style Library")
                    {
                        clientContext.Load(list);
                        clientContext.ExecuteQuery();
                        clientContext.Load(list.RootFolder);
                        clientContext.Load(list.RootFolder.Folders);
                        clientContext.ExecuteQuery();
                        documentLibraryStructureTreeView.ShowLines = true;
                        TreeNode LibraryNode = new TreeNode(list.Title);
                        documentLibraryStructureTreeView.Nodes.Add(LibraryNode);
                        Folder root = list.RootFolder;
                        FillTreeViewNodes(root, LibraryNode, clientContext);
                    }
                }
                catch
                {
                }
            }
        }

        public void FillTreeViewNodes(Folder SubFolder, TreeNode MainNode, ClientContext clientcontext)
        {
            clientcontext.Load(SubFolder.Files);
            clientcontext.ExecuteQuery();
            foreach (Microsoft.SharePoint.Client.File Fol in SubFolder.Files)
            {
                TreeNode SubNode = new TreeNode(Path.ChangeExtension(Fol.Name,string.Empty));
                MainNode.ChildNodes.Add(SubNode);
            }
        }

Wednesday, 4 September 2013

Convert Excel To PDF Using Microsoft.Office.Interop.Excel

private void ExportExcelToPDF()
        {
            string sourceFilePath = @"SourceFilePath";
            string destinationFilePath = @"DestinationFilePath";

            Microsoft.Office.Interop.Excel.Application myExcelApp;
            Microsoft.Office.Interop.Excel.Workbooks myExcelWorkbooks = null;
            Microsoft.Office.Interop.Excel.Workbook myExcelWorkbook = null;


            try
            {
                object misValue = System.Reflection.Missing.Value;
                myExcelApp = new Microsoft.Office.Interop.Excel.Application();

                myExcelApp.Visible = true;
                object varMissing = Type.Missing;
                myExcelWorkbooks = myExcelApp.Workbooks;

                //if file already exist then delete the file
                if (System.IO.File.Exists(destinationFilePath))
                {
                    System.IO.File.Delete(destinationFilePath);
                }


                myExcelWorkbook = myExcelWorkbooks.Open(sourceFilePath, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);

                myExcelWorkbook.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF,
                                    destinationFilePath, Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityStandard,
                                    varMissing, false, varMissing, varMissing, false, varMissing);


                myExcelWorkbooks.Close();
                myExcelApp.Quit();
            }
            catch
            {
            }
            finally
            {
                myExcelApp = null;
            }

        }