Sunday, April 6, 2014

Execute Server Process from Server Side Code

Sometimes when dealing with certain scenarios, there comes the question, whether a server side process execution could be initiated through server side code. This could be done. In fact this could be done in SharePoint. The code needs to be run withing elevated privileges.



Process proc = new Process();
proc.StartInfo.FileName = string.Concat(ConfigurationManager.AppSettings["Get The File Path"].ToString(), "MYExecutable.exe");
 proc.StartInfo.Arguments = "\"" + ConfigurationManager.AppSettings["argumentOne"].ToString() + file.Name + "\"" + " -o \"" + ConfigurationManager.AppSettings["argumentTwo"].ToString() + myFile + "\"";

proc.StartInfo.UseShellExecute = false;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.RedirectStandardOutput = true;

proc.Start();
proc.WaitForExit();


Saturday, April 5, 2014

ASP.Net Repeater

Rendering a simple repeater

As this is a sample app, prepare a data source. In this example I have come up with a basic DataTable.

            DataTable table = new DataTable("SelectionTable");
            table.Columns.Add(new DataColumn("Name", typeof(string)));
            table.Columns.Add(new DataColumn("Email", typeof(string)));
            table.Columns.Add(new DataColumn("Address", typeof(string)));
            table.Columns.Add(new DataColumn("Phone", typeof(string)));


1)  Add a repeater in the aspx page

The tag in the aspx page when the repaeter is added will be as :

<asp:Repeater ID="EmployeesRepeater" runat="server">

2) Set the Data source to the repeater. 

Here, I set it at the page load method in the code behind page.

            if (table != null)
            {
                //Sample data
                table.Rows.Add("Shaamil", "shaamil@abc.com", "111 aaa", "0111");
                table.Rows.Add("Joe", "joe@abc.com", "222 bbb", "0222");
                table.Rows.Add("Ramesh", "samesh@abc.com", "333 ccc", "0333");
                table.Rows.Add("Rushdi", "rushdi@abc.com", "444 ddd", "0444");
                table.Rows.Add("Sam", "sam@abc.com", "555 eee", "0555");

                //Bind data source
                EmployeesRepeater.DataSource = table;
                EmployeesRepeater.DataBind();
            }

3) Formatting the repeater rendering

<asp:Repeater ID="EmployeesRepeaterrunat="server">
   <HeaderTemplate>
     <ul>
  </HeaderTemplate>
  <ItemTemplate>
    <li>
      <span>
          <%# DataBinder.Eval(Container.DataItem, "Name") %>  &nbsp;
          <%# DataBinder.Eval(Container.DataItem, "Address") %>
      </span>
    </li>
  </ItemTemplate>
  <FooterTemplate>
   </ul>
  </FooterTemplate>
</asp:Repeater>


Result