Saturday, 20 February 2016

Create Unique Value in SSRS Dropdown Parameter

Public Shared Function RemoveDuplicates(parameter As Parameter) As String()
Dim items As Object() = parameter.Value

System.Array.Sort(items)

Dim k As Integer = 0

For i As Integer = 0 To items.Length - 1

If i > 0 AndAlso items(i).Equals(items(i - 1)) Then
Continue For

End If
items(k) = items(i)

k += 1
Next

Dim unique As [String]() = New [String](k - 1) {}

System.Array.Copy(items, 0, unique, 0, k)

Return unique
End Function






Add in Available value this code


=Code.RemoveDuplicates(parameter!dummyparameter)

change webpart header bg and color

<style>
.ms-WPHeader
{

background-color:green;

}
.ms-WPTitle A
{
  color:white !important;
}
</style>

Change the redirection behavior using jQuery on Submit button in sharepoint ListItem




<script>

$(document).ready(function() {

    var button = $("input[id$=SaveItem]");
    // change redirection behavior
        button.removeAttr("onclick");
        button.click(function() {
            var elementName = $(this).attr("name");
            var aspForm = $("form[name=aspnetForm]");
            var oldPostbackUrl = aspForm.get(0).action;
            var currentSourceValue = GetUrlKeyValue("Source", true, oldPostbackUrl);
            var newPostbackUrl = oldPostbackUrl.replace(currentSourceValue, "MyRedirectionDestination.aspx");

            if (!PreSaveItem()) return false;
            WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostbackUrl, false, true));
        });
   
});
</script>

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')