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();