Friday, December 30, 2011

This code for retrieving the First Name and Last Name from the SharePoint 2010 User Profile Service. Here I determine the currently logged in user through SPWeb class's CurrentUser attributes This code will be useful when you have your own attributes on sharePoint User Profile. Need to specify the internal name of the column.
                SPSite site = SPContext.Current.Site;
                SPWeb web = SPContext.Current.Web;
                SPServiceContext serviceContext = SPServiceContext.GetContext(site);
                UserProfileManager manager = new UserProfileManager(serviceContext);
                UserProfile profile = manager.GetUserProfile(web.CurrentUser.LoginName.ToString());
                ProfileValueCollectionBase baseVal = profile.GetProfileValueCollection("FirstName");
                ProfileValueCollectionBase baseVal = profile.GetProfileValueCollection("LastName");

Tuesday, December 20, 2011

Creating SharePoint UI Modal Popup window using JavaScript. Here I have an gridview with data I am extracting the cell value from it and send this into URL as querystring.
 function OpenDialog(URL) {
        
         var NewPopUp = SP.UI.$create_DialogOptions();
         NewPopUp.url = URL;
         NewPopUp.width = 700;
         NewPopUp.height = 350;
         SP.UI.ModalDialog.showModalDialog(NewPopUp);
     }
GridView:

            
            
            
            
            
            
            
            
             
                 
                 
                 
              
                 
                 ');">Show Page

                 
                                        
                                        
                                        
            


        
On RowCommand method of GridView extracting the first and second value
 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            
                int index = Convert.ToInt32(e.CommandArgument.ToString());
                GridViewRow selectedRow = GridView1.Rows[index];
                TableCell  docType = selectedRow.Cells[1];
                TableCell documentName = selectedRow.Cells[2];
                ListItem item = new ListItem();
                item.Text = Server.HtmlDecode(selectedRow.Cells[2].Text);
                
            
            
        }

Saturday, December 10, 2011

Reading DataRow into Generic class

Recently I worked out for an business requirement to split the number of rows as per the value.
Example if a purchase order contains number of quantity as 5.Then my code should create the 5 records on the same purchase order and splitting the quantities as 1.
Here is an XML file:



  
    004
    Samsung Galaxy Tab
    1
      
  
  005
  iPhone
  1
  
  
    006
    Nokia
    2
  

  
    007
    Motorola Razer Tab
    5
  
  
Here I read these records into generic class and identifying the each product's quantity.So there will be 9 record generated. Always best practice to read the Data Row in to generic class.
public class ExcelColumns
{
 public ExcelColumns(string PID,string PName,int PQN)
 {
        this.ProductID = PID;
        this.ProductName = PName;
        this.Quantity = PQN;
 }

    private string pId, pName;
    private int quantity;
    public string ProductID
    {
        get { return pId; }
        set { pId = value; }

    }

    public string ProductName
    {
        get { return pName; }
        set { pName = value; }
    
    }

    public int Quantity
    {
        get { return quantity; }
        set { quantity = value; }

    }

}
Reading the each row and applying the logic here
      DataSet ds = new DataSet();

        ds.ReadXml(@"D:\SPProjects\First\Products.xml");
        List list = new System.Collections.Generic.List();
        foreach (DataRow row in ds.Tables[0].Rows)
        {
            if (Convert.ToInt32(row[2]) == 1)
            {
                list.Add(new ExcelColumns(row[0].ToString(), row[1].ToString(), Convert.ToInt32(row[2])));
            }
            else
            {
                int a = Convert.ToInt32(row[2]);

                for (int b = 0; b < a; b++)
                {

                    list.Add(new ExcelColumns(row[0].ToString(), row[1].ToString(), 1));
                }

            }

        }

        GridView1.DataSource = list;
        GridView1.DataBind();

Wednesday, December 07, 2011

Creating QR code using ASP.NET form


Creating QR code using ASP.NET  form.

        string name = TextBox1.Text.ToString() + "\n";
        string age = TextBox2.Text.ToString() + "\n";
        string profession = TextBox3.Text.ToString();
        string s = name + age + profession;
        txt.Text = s;
        System.Net.WebClient client = new System.Net.WebClient();
        byte[] b = client.DownloadData("https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=" + txt.Text.ToString());

        Stream stream = new MemoryStream(b);
        System.Drawing.Bitmap bmb = new System.Drawing.Bitmap(stream);
        bmb.Save("C:\\windows\\3.png", ImageFormat.Png);
        stream.Dispose();
        stream.Flush();

Wednesday, October 05, 2011

Listing all files inside subfolders in SharePoint

This code will loop all the files inside the all subfolders of Shared Documents library in SharePoint 2010.

public ArrayList getfilesinfoder()
{
ArrayList al1 = new ArrayList();
string[] arr = LoopAllFolder();

SPSite site = SPContext.Current.Site;
for (int i = 0; i < arr.Length; i++)
{
SPFolder cols = site.OpenWeb().GetFolder("site.Url"+/Shared%20Documents/" + arr[i].ToString());
SPFileCollection files = cols.Files;
foreach (SPFile file in files)
{
al1.Add(file.Name.ToString());
}
}
return al1;
}

Friday, September 30, 2011

SPWorkflow Status programmatically

I have an document folders which associated with multiple workflows,This code snippet find the specific workflow name and its status.
This code has been developed for my requirement,I need to copy the document to another folder as soon as "Workflow completed".
Associated with List Workflow events in event receiver template.

public override void WorkflowCompleted(SPWorkflowEventProperties properties)
{
using (SPSite site = new SPSite(properties.WebUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = properties.ActivationProperties.List;
foreach (SPListItem item in list.Items)
{
foreach (SPWorkflow wf in item.Workflows)
{

if (list.WorkflowAssociations[wf.AssociationId].Name.ToString() == "MultipleTasksFlow")
{

string WFStatus = item[list.WorkflowAssociations[wf.AssociationId].Name].ToString();

}
}

}

}

}

base.WorkflowCompleted(properties);

}

Saturday, September 10, 2011

Getting SPWeb ref inside workflow programmatically

If you want to get SPWeb reference inside the OnTaskChanged_Invoked or Task_MethodInvoking
method

SPWorkflowActivationProperties workflowProperties= new SPWorkflowTaskProperties();
SPWeb web = workflowProperties.Web;

you can get the SPWeb properties of "SPWorkflowActivationProperties" class.
SPContext or HttpContext will not works inside the SharePoint Workflow.

This single line snippet saved my lot of developing hours to trigger the workflow programmatically.

Thursday, September 08, 2011

Creating SubFolder in SharePoint 2010

Creating SubFolder in SharePoint 2010
n1="FolderName";           
SPList list = site.Lists.TryGetList("Shared Documents");
           SPFolderCollection cols = list.RootFolder.SubFolders;
           SPFolder docFolder =
 cols.Add("/Shared Documents/" + n1);

Monday, August 22, 2011

The default term store cannot be identified

I was trying to activate the Taxonomy on my site which created from the blank site template.When I connecting and add some properties for "Managed Meta data service" from Central application I have got this error.Initially I have no clue.I googled its WCF hotfix for service application.

when creating the "Enterprise Keyword" column,my term store was not able to find the default term store.
"The default term store cannot be identified"
After tried some attempts to create the same column below error was thrown.
Unrecognized attribute 'allowInSecureTransport'


You can download the hotfix from the below link

http://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=23806

Enable Enterprise keywords colum in site

Enabling the "Enterprise Keywords" in sharepoint list or document library.
If you are not seeing this column by default,the reason was you have been selected the blank site to create root site.
There are no way to activate this feature if you selected the blanksite.
You need to activate it through stsadm command

STSADM -o activatefeature -n TaxonomyFieldAdded -url http://myserver
before activating this feature please be make sure you activated the site featured called "SharePoint Server Enterprise Site features"

Sunday, August 21, 2011

SPFolder Collection in SharePoint 2010

This code loop all the folders inside the "Shared Documents" folder.
It will retrieve all the folders inside the Shared documents.I have an requirement to allow the user to upload the documents in to managed folder into Shared Documents and trigger the Workflow.Soon I will post the Workflow code.
public string[] LoopAllFolder()
        {
            string folderName = "";
            SPSite site = SPContext.Current.Site;
            SPFolder cols = site.OpenWeb().Folders[site.Url + "/Shared Documents"];
            if (cols.SubFolders.Count > 0)
                    {
                        //SPFileCollection files = cols.Files;
                        SPFolderCollection folders = cols.SubFolders;
                        foreach (SPFolder Colsfolders in folders)
                        {
                            folderName = folderName + Colsfolders.Name.ToString() + ",";
                        }

                    }
            return folderName.TrimEnd(',').Split(',');
          
                }

                
        }


I bind these folders in dropdownlist by removing the "Forms" folder.
List FolderList = new List(LoopAllFolder());
            FolderList.RemoveAt(0);
            ddlList.DataSource = FolderList;
            ddlList.DataBind();

Wednesday, August 17, 2011

Looping the people picker values

Recently I encountered the strange error while retrieving the all user from the
People picker control using SPQuery.
My datatable comes with Site user id and Name.As I wanted to assign these user to a
specific task in workflow.
while using these first user comes without site user id and the remaining were perfect as i expected.
I should admit,I tried many times but could not figure it out for my first user comes along with site id.Finally I made it to work.

Firstly queried the all user from the people picker control with certain condition using CAML.
 private string GetApproverList()
        {
            using (SPWeb web = workflowProperties.Web)
            {
                string appList = "";
                SPList docApproverList = web.Lists["DocApprovers"];
                
                string DocType = workflowProperties.Item["DocumentType"].ToString();               
                SPQuery q = new SPQuery();
                
                //q.Query = q.Query = "" + DocType + "";
                q.Query = "" + DocType + "";
                DataTable dt = docApproverList.GetItems(q).GetDataTable();
                foreach (DataRow row in dt.Rows)
                {
                    appList = appList + row["Approvers"].ToString()+",";
                }
                return appList.TrimEnd(',');
            }
        }


Secondly split this string into array by passing the comma sperator and '#' separator.
 string DocListUser = GetApproverList();
            string[] uids = DocListUser.Split(';', '#');
            for (int a = 0; a < uids.Length; a++)
            {
                if (uids[a].ToString() != "" && !CheckNumber(uids[a].ToString()))
                {
                    uidsList.Add(uids[a]);
                }

            }
Now I have final string array which comes with "",user id and display name.
public bool CheckNumber(string value)
        {

            int number1;
            return int.TryParse(value, out number1);
        }
I used array list to add each items in above string.Then I omit the "" string and numbers in the array.
 foreach (var userList in uidsList)
            {
                SPUser user = SPContext.Current.Web.EnsureUser(userList.ToString());
                assignees.Add(user.LoginName);
            }

Wednesday, July 06, 2011

How to Find the Holidays in given date range

I was working with fully date time format around to develop the attendance system.
I need to ignore the Weekend days and other government announced holiday list.
This will used to find the day was a holiday or not in the given date range.
 public DataSet ShowHolidays()
    {

        DataSet ds = new DataSet();
        ds.ReadXml(@"D:\\holiday.xml");
        return ds;
    }
I am maintaining the holiday list xml file

2011/07/04
2011/07/05
2011/07/06

 ArrayList list = new ArrayList();
 public bool IsHolidays(DateTime dt1)
    {
        DataSet d1 = ShowHolidays();
        foreach (DataRow row in d1.Tables[0].Rows)
        {
            list.Add(Convert.ToDateTime(row["Dates_Text"]).ToShortDateString());

        }
        return list.Contains(dt.ToShortDateString());
    }

How to find the WeekEnd days in C#

This code snippet will used to find out the WeekEnd days in C#.Once you find out then you can write your own business requirement logic to be build.
  public bool isWeekEnd(DateTime dt)
    {
        if (dt.DayOfWeek == DayOfWeek.Saturday || dt.DayOfWeek == DayOfWeek.Sunday)
        { return true; }
        else
        { return false; }

    }


Tuesday, July 05, 2011

Enumerating different items from Arrays

This morning I started to working on some thing to compare the two array list or array values and identifying the similarities and differential items.
The below code is equivalent to looping the both arrays and identifying the common and different items in two array values.


In C#.NET 3.5 We have Intersect and Except extension method to get solution for these kind scenarios.
List List1 = new List();
List1.Add("Murugesan");
List1.Add("Geetha");
List1.Add("GuruSelvam");


List List2 = new List();
List2.Add("Murugesan");
List2.Add("Geetha");


List exce = List1.Except(List2).ToList();
foreach (string n in exce)
{
Response.Write(n.ToString());
}
//It will returns the GuruSelvam

Monday, July 04, 2011

export sharepoint site

Today i learned some more deeply about site collection data backup with all attributes of sites such as versions of contents,security permission level.file compression during export and import of the site using sharepoint 2010 powershell cmdlets.
I am on preparing for the exam 70-667 sharepoint 2010 configure.i always use the beckybertram blog for microsoft exam preparation.


Friday, July 01, 2011

C# SMTP email sending code

When I tested this code in webapplication its works fine.But my webmail server is HTTPS based and I wanted to integrate this into my SharePoint webpart.

In this case,set EnableSsl true on your smtp object and specify the port number if you are not using the SMTP's default port 25.

Still you got an error use the below code to off the Certificate Validation while relying on HTTP.
If you are an developer and testing it on the PC where you installed "fiddler".Just make sure its Off.
Use the below line just before to Send method.
 System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }; 
try
        {
            MailMessage mail = new MailMessage();
            SmtpClient smtp = new SmtpClient("webmail smtp");

            mail.From = new MailAddress("user@webmail.com");
            mail.To.Add("murugesa.pandian@webmail.com");
           
            mail.CC.Add("CC");

            mail.Subject = "Subject";
            mail.Body = "Email contents";


            smtp.Credentials = new System.Net.NetworkCredential("userid", "pwd");
            smtp.EnableSsl = true;

            smtp.Send(mail);
            Response.Write("Sent !");
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message.ToString());
        }


Wednesday, June 22, 2011

Binding Month days in DropDownList

public void BindDays()
{
for (int i = 1; i <= 31; i++)
{
ListItem item = new ListItem();
item.Value = i.ToString();
item.Text = i.ToString();
DropDownList1.Items.Add(item);
}
}

My virtual business card

Learn more about me !
https://www.mcpvirtualbusinesscard.com/VBCServer/passionate/profile

Monday, June 20, 2011

Calculating monthwise leaves in date range in C#.NET

Recently there was an requirement at my work was finding the leave month wise.
Assume this way,If an employee apply leaves for the duration between 4th Feb,2011 and
4th July 2011.HR team wanted to calculate the month wise leave for that employee against total number of leave days.
By doing this way there is a room to not to calculate the "Week end" and other government announced holidays.

Here is the code for to do so.

class Program
{


static void Main(string[] args)
{
MonthChecker cObj = new MonthChecker();
List listDate = new List();


List strList = new List();

DateTime from = new DateTime(2011, 02, 25);
DateTime to = new DateTime(2011, 04, 14);


DateTime dt2 = new DateTime(2011,02,25);
DateTime to2 = new DateTime(2011, 06, 14);

string n = "";
string n1 = "";

while (from <= to)
{
from = from.AddDays(1);
DateTime d = new DateTime();
d = from.AddDays(-1);
if (cObj.CheckMonthLastDay(d))
{

listDate.Add(d);
}

}

for(int i=0;i
{

if (i == 0)
{
TimeSpan span = listDate[i].Subtract(dt2);
n = n + "\n" + span.Days.ToString();
strList.Add(n);
}

else
{
DateTime ck = new DateTime(listDate[i].Year, listDate[i].Month, 01);
TimeSpan spanck = listDate[i].AddDays(1).Subtract(ck);
string M = spanck.Days.ToString();
strList.Add(M);
}

}

foreach (string str in strList)
{
Console.WriteLine(str);
}
Console.ReadLine();

}
}

Class MonthChecker
{
public DateTime GetLastDayOfMonth(DateTime dtDate)
{

int a = DateTime.DaysInMonth(dtDate.Year, dtDate.Month);
DateTime dt = new DateTime(dtDate.Year, dtDate.Month, a);
return dt;

}
public bool CheckMonthLastDay(DateTime dtDate)
{
DateTime d1 = dtDate;
if (d1 == GetLastDayOfMonth(dtDate))
{
return true;
}
else
{
return false;
}
}

}

Friday, June 17, 2011

Find Number of Days in specific month

Recently I encountered the situation to find the number of days in specific month of the given year.In ASP.NET 3.5 comes up with built-in method called "DaysInMonth".This method takes two parameter as Year and Month.
If you want to find out the number of days for "January",then pass the value 1 for Month parameter.
int numberOfDays = DateTime.DaysInMonth(Convert.ToInt32(YearList.SelectedItem.Value), Convert.ToInt32(MonthList.SelectedItem.Value))

retrieve unique rows from sharepoint List

To retrieve the unique rows from the sharepoint list use the "DefaultView" of the DataTable.
public DataTable GetLeaveAppliers()
        {
 using (SPSite site = new SPSite(SPContext.Current.Site.Url))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["Leave Plan"];
                    SPQuery q = new SPQuery();
                    string query = "";
                    q.Query=query;
                    DataTable dt = list.GetItems(q).GetDataTable();
                    DataTable row= dt.DefaultView.ToTable(true, "Author");


                    return row;


                }

            }
}

Monday, June 06, 2011

ListItem Client OM

Listing all items in sharepoint list usingClient Object Model in SharePoint 2010(Client OM)
ClientContext cntx=new ClientContext("Site URL");
Web web = cntx.Current.Web;
List list=web.Lists.GetByTitle("List Name");
CamlQuery query=new CamlQuery();
query.ViewXML="";
ListItemCollection cols=list.GetItems(q);
cntx.Load(cols);
foreach(var item in cols)
{
list1.Items.Add(item["Title"]);
}
cntx.ExecuteQuery();

Friday, June 03, 2011

SharePoint 2010 Delegate Control

SharePoint 2010 Delegate Control

This control delegates asp.net control to render inside its template.
In your home page of the sharepoint site you can see the "MySite,Search Input box with lens icon and "Global Navigation".
These controls are called "Delegate Controls".You can create new asp.net web controls or user control and put
them inside the delegate template.Your customised user control will be render as per your sequence specified in
"Element.xml" of the sharepoint project solution.
If you want host multiple user controls in "Delegate template" then set the property of the Control "AllowMultipleControls" to true.
This will allow the delegate control consider as "Child control" as per the sequence.
The Lower sequence will always replace the highest sequence in rendering mode.
If you create the user control refer the controlSrc[usually it will be the virtual directory of ControlTemplate(_controltemplates) ]properties of "Control" in Element.xml
My Element.xml belows like.


  


on my UserControl's on Click of the Button events I just simply placed an javascript alert.
this.Page.ClientScript.RegisterClientScriptBlock(Page.GetType(),"Greetings", "Type your script");
You can set scope on your "Feature File"

Tuesday, May 31, 2011

How to generate live data for chat webpart in sharepoint 2010

How to generate the live data for "Chart WebPart in SharePoint 2010" using SharePoint List.
Visit
http://www.codeproject.com/KB/TipsnTricks/LiveData_ChartWebPart.aspx

Tuesday, May 24, 2011

updating sharepoint list programmatically

updating sharepoint list programmatically
Recently I encountered the new requirement which wanted to create "Import SharePoint List"
There were more than 700 rows to be updated on a column value had null.
try
            {
                SPSite site = SPContext.Current.Site;
                SPWeb web = site.OpenWeb("http://mosstemp:5000");
                SPList list = web.Lists["Prospects"];

                SPQuery query = new SPQuery();
                query.Query = "";
                SPListItemCollection items = list.GetItems(query);

                foreach (SPListItem item in items)
                {

                    item["Status"] = "Not Called";
                    item.Update();

                }
               
                control = new LiteralControl();
                control.Text = "Updated";
            }
            catch (Exception ex)
            {
                control.Text = ex.InnerException.Message.ToString();
            }
You can't update the "look up" column in the sharepoint list.

Tuesday, May 17, 2011

Retrieve List Item using SharePoint Client Object

This code retrieve the sharepoint list item using SharePoint Client Object Model
ClientContext context = new ClientContext("http://WIN-ASNOSC246SV");
var web = context.Web;
context.Load(web);

List list = web.Lists.GetByTitle("Friends");
context.Load(list);

CamlQuery query = new CamlQuery();
query.ViewXml = "";
ListItemCollection cols = list.GetItems(query);
context.Load(cols);

ListItem item = cols.GetById(1);
context.Load(item);

context.ExecuteQuery();
Response.Write(item["Name"].ToString());

Wednesday, May 11, 2011

Feel Good about myself

This is my first attempt to take MS 70-667 SharePoint configuration and Maintenance exam on "MeasureUp.com".When I test my knowledge on these topic on trial test engine page on my attempt,I have passed with 80%.I am really feel good about myself.:)-

Monday, May 09, 2011

SharePoint Claim based Identity

Assume you have an SharePoint web application which build on "Claim based Authentication"

When user requested the page or Sharepoint documents using web browser,SharePoint will check the user has been authorised or not.
If it is not authorised,It will send back to user with requested URL,in turn user's request will be redirected to "Identity Provider".It can be Active Directory or "ASP.NET Membership Provider".
Once your credentials are validated by "Identity Providers" you will be given a token to which will allow your request to be authenticated by SharePoint.

Friday, May 06, 2011

Listing all Folder in SharePoint 2010

To list all the "Folders" in a site or web in SharePoint 2010
SPSite site = SPContext.Current.Site;
            SPFolderCollection cols =  site.OpenWeb().Folders;
            foreach (SPFolder folder in cols)
            {
                ListBox1.Items.Add(folder.Name.ToString());
            }

Thursday, May 05, 2011

WCF error in SharePoint 2010



I was about to consume the SharePoint 2010 List WCF service on my web application using jSon.
When I tried this link http://serverName:8056/_vti_bin/ListData.svc
on my sharepoint environment,I got this error saying "Could not load type "System.Data.Services.Providers.IDataServiceUpdateProvider".

To resolve this issue
Apply : the batch update
http://support.microsoft.com/kb/976127

Wednesday, May 04, 2011

Downloading the SharePoint Document

Recently,a strange scenario in SharePoint 2010 development I faced.
I created a Visual WebPart with sandbox solution based to let user download the files from the SharePoint Document Library.
Labour the lines of code to get reference of the SPFile from the current web context.
Reading and Writing the file contents into streams to let user to download the file as soon as they clicked it on the "Download" link.It will prompts the "File Download Dialog box".
I deployed it on the sharepoint development environment it just works fine.
Later,I came to know that webpart is not allowing the end user to download.
Again I checked the same webpart performance and put optimised looping and disposing the objects verily stated manner.
Its works fine as I expected.But When I deployed it on SharePoint Server,I faced the same problem when user accessing the page.
When end user clicks the link "Download",Browser redirect to "Forbidden page".

Finally I have concluded the user is only "Reader" permission group.

Simply added RunWithElevatedPrivileges
Its works fine for all user group permission.
protected void Button1_Click(object sender, EventArgs e)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
FileAction();
});
}
protected void FileAction()
{
SPWeb site = SPControl.GetContextWeb(Context);
SPFile spFile = site.GetFile(site.Url + "/DocLibrary/" + "1.txt");
// Above line for clarity purpose hard coded.You can read the file name from the //library.My requirement there was only one file.
FileStream fs = new FileStream("C:\\Windows\\Temp\\tempContents.txt", FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(spFile.OpenBinary());
bw.Close();
fs.Close();

using (FileStream sm = File.Open("C:\\Windows\\Temp\\tempContents.txt", FileMode.Open))
 {
using (StreamReader sr = new StreamReader(sm))
{
Response.AppendHeader("Content-Disposition", "attachment; filename =" + spFile.Name);
Response.ContentType = "text/plain";
using (StreamWriter sw = new StreamWriter(Response.OutputStream))
{
sw.Write(sr.ReadToEnd());
}
}
sm.Close();
Response.Flush();
Response.Close();
}
}

Wednesday, April 20, 2011

decimal control in double value

There were situation double values are to be controlled only to 3 decimal or 2 decimal.
This one line code does the exact function.
        double d = 42.566454648;
        double d1 = 23.545548125;
        double d2 = d + d1;
        Response.Write(d2.ToString("N3"));

Monday, April 11, 2011

two column filtering - AND CAML

Filtering the rows on two column condition on CAML query





India




Chennai




I have a sharepoint list contains the columns
Country | City | Price1 | Price2|
Records will be
India | Chennai | 254.3 | 536.5
UAE | Dubai | 500.24| 65.21

Thursday, February 24, 2011

MVC2 Template Helpers

Templated Helpers

In ASP.NET MVC 2.0 newly added feature is Templated Helpers.This allows you to create display screens and
editable screens.
It strongly supports the refactoring,intellisense and compile time checking.
<%= Html.DisplayFor(m => m.Name) %>
Alternatively you can try the
Html.EditorFor()
<%= Html.LabelFor(m =>m.Name) %>

Friday, February 18, 2011

SharePoint 2010 Developer Dashboard

This will allows the developer to detect the critical modules, web parts and queries in the hosted SharePoint applications.
It lets the developer to analyses the each request and response’s time and each method’s responding time.
So the developer can easily locate the errors and resolve them.

To Activate this feature through stsadm tool

Stsadm -o setproperty -pn developer-dashboard -pv on

after these command you will get "Operation Successful" message.


To Deactivate
Stsadm -o setproperty -pn developer-dashboard -pv off

Thursday, January 27, 2011

C# - New line constant

String AccountName = "DomainNAme\\" + TextBox1.Text.ToString() + "." + TextBox2.Text.ToString();

Monday, January 17, 2011

SPListItem updating programmatically

After multiple attempts of opening the site using SPSite class,I could not make it happen.But searching of these topics i learned many tips and idea to resolve my task.
My requirement was having on webpart there I must create the Form to be filled by end user.These will be inserted into SharePoint List.
In Visual webpart I used the below code
 SPSite site = SPContext.Current.Site;
               SPWeb web = site.OpenWeb();
                SPList myList = web.Lists["List OF Employee"];
                SPListItem Item = myList.Items.Add();
                Item["Title"] = TextBox1.Text;
                Item["Name"] = TextBox2.Text;
                Item.Update();