Saturday, 20 February 2016

Add Connection String in Share point TimerJob from web.config file

 add connection string in SPTIMERJOB  




Step -1

add .dll references

Microsoft.SharePoint.Client.ServerRuntime
Path
C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.ServerRuntime.dll
System.Configuration
path
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Configuration.dll
System.Web
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Web.dll

Step -2    

add namespace

using System.Web.Configuration;
using System.Configuration;




SPWebApplication webApplication = this.Parent as SPWebApplication;
Configuration config = WebConfigurationManager.OpenWebConfiguration("/", webApplication.Name);
string conStr = config.ConnectionStrings.ConnectionStrings["myConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(conStr);

Monday, 21 April 2014

hide yellow color title bar in sharepoint site

in master page type  style="display:none"


<div id="s4-statusbarcontainer" style="display:none">

hide quick launch leftpanel


if you want to hide Quick Launch  only on single site page then add a content editor webpart and paste the below script



<style type="text/css">
/*--Hide Quick Launch --*/
#s4-leftpanel {
 display: none;
}
.s4-ca {
 margin-left: 0px;
}
</style>


or you want to hide complete Quick Launch from left side then paste in site master page

how to extract people picker field in get name,email,id,loginid etc

string string2 = Convert.ToString(item["collName"]);
SPFieldUserValue userValue = new SPFieldUserValue(web,string2);
                                 
                                   string     userName = userValue.User.Name;
                                 
                                   string     MailAddress = userValue.User.Email;
                                  

copyto method in sharepoint

public void CopyList(SPList src)
{
    //Copy items from source List to Destination List
    foreach (SPListItem item in src.Items)
    {
        if(isUnique(item.UniqueId))
        {
          newDestItem = DestinationList.Items.Add();

          foreach (SPField field in src.Fields)
          {
             try
              {
                if ((!field.ReadOnlyField) && (field.InternalName!="Attachments"))
                  newDestItem[field.InternalName] = item[field.InternalName];
               }
             catch (Exception ex)
              {
              //you should save the "ex" somewhere to see its outputs
               ex.ToString();
              }
           }
           newDestItem.Update();  //only now you call update!
        }
       }
      } 

how to copy list item attachment to library in sharepoint

using (SPSite site = new SPSite("http://server:name/sites/"))
                {
                    site.AllowUnsafeUpdates = true;
                    using (SPWeb webApp = site.OpenWeb())
                    {
                        webApp.AllowUnsafeUpdates = true;
                        SPList list = webApp.Lists["list"];
                        SPQuery query = new SPQuery();
                        query.Query = @"<OrderBy> <FieldRef Name='ID' Ascending='FALSE' /></OrderBy>";
                        SPListItemCollection itemCollection = list.GetItems(query);
                        SPListItem sourceItem = itemCollection[0];
                        SPFolder mylibrary = webApp.GetFolder("Meeting Documents");
                        // Copy Attachmets from source list to destination Library
                            if (sourceItem.Fields.ContainsField("Attachments"))
                            {
                                foreach (string fileName in sourceItem.Attachments)
                                {
                                  SPFile file = sourceItem.ParentList.ParentWeb.GetFile(sourceItem.Attachments.UrlPrefix + fileName);
                                  byte[] imageData = file.OpenBinary();
                                  webApp.Files.Add("Shared%20Documents/" + System.IO.Path.GetFileName(file.Url), imageData,true);
                               
                                }
                         
                            }
                        webApp.AllowUnsafeUpdates = false;
                    }
                    site.AllowUnsafeUpdates = false;
                }

how to change date format in xslt using sharepoint designer

put in Formula Editor in sharepoint designer


ddwrt:FormatDateTime(string(@YourDateParam) ,1033 ,'dd/MMM/yyyy')

Monday, 2 December 2013

How to Use Greater Than and Less Than in CAML with Where

How to Use Greater than and Less than in CAML




SPQuery query = new SPQuery();
                    query.Query = @"<Where>
      <And>
         <And>
            <Or>
               <And>
                  <Geq>
                     <FieldRef Name='FromDate' />
                     <Value Type='DateTime'>2013-11-13T12:00:00Z</Value>
                  </Geq>
                  <Leq>
                     <FieldRef Name='FromDate' />
                     <Value Type='DateTime'>2013-12-03T12:00:00Z</Value>
                  </Leq>
               </And>
               <Geq>
                  <FieldRef Name='ToDate' />
                  <Value Type='DateTime'>2013-11-13T12:00:00Z</Value>
               </Geq>
            </Or>
            <Leq>
               <FieldRef Name='ToDate' />
               <Value Type='DateTime'>2013-12-03T12:00:00Z</Value>
            </Leq>
         </And>
         <Eq>
            <FieldRef Name='Column1' />
            <Value Type='Text'>f2</Value>
         </Eq>
      </And>
   </Where>";

Monday, 25 November 2013

Fetch Data using LINQ in Sharepoint programatically

Fetch Data using LINQ in Sharepoint



                    SPList List = web.Lists["abc"];
                     var checkin = from SPListItem p in List.Items
                                   //&& p["col1"].ToString().ToLower() ==facility
                                where  p["col2"].ToString().ToLower() ==val1.ToLower() && p["Room"].ToString().ToLower() == room  && Convert.ToDateTime(p["fromDate"].ToString()) >=dtIn && Convert.ToDateTime(p["FromDate"].ToString()) < dtOut
                   
                                 select p;
                 

Sunday, 24 November 2013