Search This Blog

Monday, November 28, 2011

GetFilterRecords from SP with date and field


 public DataTable GetFilterRecords(DateTimePicker frmDate, DateTimePicker toDate, string migMode)
        {
            try
            {
                using (ClientContext clientContext = new ClientContext(SiteUrl))
                {
                    
                    Web oweb = clientContext.Web;
                    List olist = clientContext.Web.Lists.GetByTitle("Migration Log");
                    CamlQuery camlQuery = new CamlQuery();
                    camlQuery.ViewXml = "<View><Query><Where><And><Eq><FieldRef Name='MappingMode' /><Value Type='Choice'>" + migMode + "</Value></Eq><And><Geq><FieldRef Name='Created' /><Value Type='DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(frmDate.Value) +"</Value></Geq><Leq><FieldRef Name='Created' /><Value IncludeTimeValue='FALSE' Type='DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(toDate.Value) +"</Value></Leq></And></And></Where></Query></View>";
                    ListItemCollection olistcoll = olist.GetItems(camlQuery);
                    clientContext.Load(olist);
                    clientContext.ExecuteQuery();
                    clientContext.Load(olistcoll);
                    clientContext.ExecuteQuery();
                    foreach (ListItem oitem in olistcoll)
                    {
                        dr = dt.NewRow();
                        dr["Src Table"] = Convert.ToString(oitem["Title"]);
                        dr["Destination List"] = Convert.ToString(oitem["DestList"]);
                        dr["Src Table Fld"] = Convert.ToString(oitem["SrcTableField"]);
                        dr["Destination List Fld"] = Convert.ToString(oitem["DestListField"]);
                        itemUrl = (FieldUrlValue)oitem["ItemUrl"];
                        if(itemUrl != null)
                        dr["ItemUrl"] = itemUrl.Url;
                        dr["Created Date"] = Convert.ToString(oitem["Created"]);
                        dr["Status"] = Convert.ToString(oitem["Status"]);
                        string cmts =  Convert.ToString(oitem["Comments"]);
                        dr["Comments"] = HtmlRemoval.StripTagsRegex(cmts);
                        dt.Rows.Add(dr);
                        oitem.Update();
                        clientContext.ExecuteQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Invalid URL" + ex);
            }
            return dt;


        }

Read Data From Excel Sheet.



public void _ExcelData(string excelFileName, ComboBox cboExcelCols, DataGridView gvExceldata)
        {
            try
            {
                FileHelper objHelper = new FileHelper(excelFileName);
                string connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0;HDR=YES;IMEX=1;""", excelFileName);
                string query = String.Format("select * from [{0}$]", "Sheet1");
                using (OleDbConnection con = new OleDbConnection(connectionString))
                {
                    con.Open();
                    OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);
                    DataTable dt = new DataTable();
                    dataAdapter.Fill(dt);
                    int cnt = dt.Columns.Count;


                    List<ExcelItemPairs> data = new List<ExcelItemPairs>();
                    foreach (DataColumn col in dt.Columns)
                    {
                        cboExcelCols.DisplayMember = "Value";
                        cboExcelCols.Items.Add(new ExcelItemPairs() { Value = Convert.ToString(col.ColumnName), Type = Convert.ToString(col.DataType), SrcName = Convert.ToString(objHelper.FileName) });
                    }


                    DataSet dataSet = new DataSet();
                    dataAdapter.Fill(dataSet);
                    gvExceldata.DataSource = null;
                    gvExceldata.DataSource = dataSet.Tables[0];
                }
            }
            catch (Exception ee)
            {


                MessageBox.Show(ee.Message);
            }
           
        }

Date convertion to SharePoint DateTime



Ref:
/* -- Format for Date Only Field -- */      
private static String ToSPDate(String strDt)
{
    if (strDt == String.Empty)
        return strDt;
    else
        return (Convert.ToDateTime(strDt)).ToString("yyyy-MM-dd");
}

/* -- Format for DateTime Field -- */
private static String ToSPDateTime(String strDt)
{
    if (strDt == String.Empty)
        return strDt;
    else
        return (Convert.ToDateTime(strDt)).ToString("yyyy-MM-ddTHH:mm:ssZ");
}
/* -- Build List WebReference CAML String -- */
String strCamlBuilder = "<Method ID='1' Cmd='Update'>";
strCamlBuilder += "<Field Name='ID'>1</Field>";
strCamlBuilder += "<Field Name='DateOnlyField'>" +ToSPDate(strDtInput) + "</Field>";
strCamlBuilder += "<Field Name='DateTimeField'>" +ToSPDateTime(strDtTmInput) + "</Field>";
strCamlBuilder += "</Method>";

Wednesday, November 16, 2011

Master Page Concept website

Authentication vs Authorization


Authentication is the process of verifying that a user has the right to access an application. The canonical example is the login screen. A successful login indicates the user is authorized and has the right to use the application. A failed login means the user does not have the right to access the application.
Authentication often precedes authorization, but doesn't always have to. For example, on Seventh Octave, I made the decision to not force readers to login to leave comments. What this means is my readers are authorized to leave comments without being authenticated.
This behavior is the same for each article - even popular articles like myJavaScript Dashboard Gauge Set.

Authorization

Authorization determines what actions a user has the right to take within an application. Here, the canonical example is Role Management.
Take for example a Blog application. A Writer role may be able to create and update Posts, but not necessarily delete Posts. So, you wouldn't authorize the Writer role to delete Posts.
On the other hand, you may have a Moderator role. As a Moderator, you can delete Comments, but you wouldn't necessarily want a moderator to create, update or delete Posts. So, you would authorize Moderators to delete Comments, but not create, update or delete Posts.
So, basically, authentication determines access, whereas authorizationdetermines actions. Now you know, and knowing is half the battle.

web application vs sitecollection


Pages are what you actually see and use on SharePoint. A Site is a collection of pages. A SiteCollection is, as the name indicates, a collection of sites. A WebApplication is a collection of SiteCollections.
SiteCollections are used to group Sites together to make it easier for you to, for example, share data between these sites.
WebApplications are useful when you need to share data between different SiteCollections.

In this context, I refer to data as any of the following:
  • User Content
  • Lists
  • Pages
  • Service Applications
  • Features
  • Anything that you might want to share between sites

web.confif connection string


 <connectionStrings>
    <add name="conStr" connectionString="Data source=<sqlserver name>; initial catalog= <DBName>;Integrated Security=True" />
    <!--<add name="conStr" connectionString="Data source=<sqlserver>; user id=sa;password=<password>;initial catalog=<DBName>;Integrated Security=SSPI;" />-->
  </connectionStrings>