Make C# window application run on Windows Startup

First of all add this to the code

using Microsoft.Win32;

then use this snippets to

RegistryKey rkApp = Registry.CurrentUser.OpenSubKey(“SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run”, true);

//Check to see the current state (running at startup or not)

if (rkApp.GetValue(“ClientServer”) != null)

{

rkApp.SetValue(“ClientServer”, Application.ExecutablePath.ToString());

}

And bingo…..  🙂

Advertisements
By Amar Trivedi Posted in ASP.NET

Authorizing User with LinkedIn and Get User Profile

Before some day my sir gave me work of authorizing users with their LinkedIn profiles. So i did some RnDs and found this 2 best examples in C#.

  1. LinkedInOAuth.rar.zip
  2. LinkedInAuth.rar.zip

Note: Please Give OAuth Redirect URL while registering your domain with LinkedIn for Key and Secret.

And in this example you will get User Profile as XML so use this code to make this xml to table format.

Here Response is a XML String.

StringBuilder output = new StringBuilder();
using (XmlReader reader = XmlReader.Create(new StringReader(response)))
{
XmlWriterSettings ws = new XmlWriterSettings();
ws.Indent = true;
using (XmlWriter writer = XmlWriter.Create(output, ws))
{
DataTable dtable = new DataTable();
DataRow dRow = dtable.NewRow();
string strElement = “”;

int count = 0;
bool enter = true;

while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
writer.WriteStartElement(reader.Name);
if (count == 0)
{
DataColumn column = new DataColumn(reader.Name);
dtable.Columns.Add(column);
strElement = reader.Name;
count++;
}
foreach (DataColumn dc in dtable.Columns)
{
if (dc.ColumnName.Equals(reader.Name))
{
enter = false;
}
}
if (enter)
{
DataColumn column = new DataColumn(reader.Name);
dtable.Columns.Add(column);
strElement = reader.Name;
}
enter = true;
break;
case XmlNodeType.Text:
writer.WriteString(reader.Value);
dRow[strElement] = reader.Value;
break;
case XmlNodeType.XmlDeclaration:
case XmlNodeType.ProcessingInstruction:
writer.WriteProcessingInstruction(reader.Name, reader.Value);
break;
case XmlNodeType.Comment:
writer.WriteComment(reader.Value);
break;
case XmlNodeType.EndElement:
writer.WriteFullEndElement();
break;
}
}
dtable.Rows.Add(dRow);
GridView1.DataSource = dtable;
GridView1.DataBind();
}
}

By Amar Trivedi Posted in ASP.NET