how to post currency code in payumoney in asp.net mvc - c#

how to post currency code as United States dollar and India. By default it uses IND.
[HttpPost]
public void Plans(UserRegistreModel model)
{
string firstName = model.FirstName;
string middleName = model.MiddleName;
string lastName = model.LastName;
string amount = Convert.ToString(model.Amount);
string Noofemp = model.NoOfEmployees;
string productInfo = "HRMS";
string email = model.Email;
string phone = model.Contact;
string FirmName = model.FirmName;
//string surl = form["txtsurl"].ToString();
//string furl = form["txtfurl"].ToString();
RemotePost myremotepost = new RemotePost();
string key = "";
string salt = "";
//posting all the parameters required for integration.
myremotepost.Url = "https://secure.payu.in/_payment";
myremotepost.Add("key", "");
string txnid = Generatetxnid();
myremotepost.Add("txnid", txnid);
myremotepost.Add("amount", amount);
myremotepost.Add("productinfo", productInfo);
myremotepost.Add("firstname", firstName);
myremotepost.Add("phone", phone);
myremotepost.Add("email", email);
//UserRegistreModel register = new UserRegistreModel();
TempData["model"] = model;
myremotepost.Add("surl", "");
myremotepost.Add("furl", "");
string hashString = key + "|" + txnid + "|" + amount + "|" + productInfo + "|" + firstName + "|" + email + "|||||||||||" + salt;
string hash = Generatehash512(hashString);
myremotepost.Add("hash", hash);
myremotepost.Post();
}

You can do things like this
myremotepost.Add("currency", "INR");
It will set the currency INR for current request.

Related

Proble with input string

I am programming in ASP.NET MVC using C# and I get this error:
The input string is not formatted correctly
I have corroborated in the database and it is fine. So I would like to know if you can see the error. I want to clarify that both the dni and dnidos are Float in the database. But for some unknown reason it is not working in the code.
Class:
public double dniDos { get; set; }
public Solicitud(double dni, string codigo, decimal? monto, string soli,
DateTime fechaSol, double? valnom, string desc,
string apellido,
string nombre,
string domicilio, string numero,
string piso, string dpto, string mono, string barrio,
string zona, string localidad, string provincia,
int? cp, string tipoDni, string fechaNac, string ocupacion,
string tel, string cel,
string email,
string estadoCivil, string observaciones,
string nomdos, double dniDos,
string codagencia, string codCobrador, string cobdom,
string ase, int cuo)
{
this.DniNumero = dni;
this.Codigo = codigo;
this.Monto = monto;
this.Solicitudes = soli;
this.fechaSol = fechaSol;
this.ValNom = valnom;
this.DescPlanActual = desc;
this.Apellido = apellido;
this.Nombre = nombre;
this.Domicilio = domicilio;
this.Numero = numero;
this.Piso = piso;
this.Dpto = dpto;
this.Mono = mono;
this.Barrio = barrio;
this.acidzona = zona;
this.Localidad = localidad;
this.Provincia = provincia;
this.CodigoPostal = cp;
this.DniTipo = tipoDni;
this.fechaNac=fechaNac;
this.ocupacion = ocupacion;
this.Telefono = tel;
this.Celular = cel;
this.email=email;
this.estadoCivil=estadoCivil;
this.observaciones = observaciones;
this.nomDos = nomdos;
this.dniDos = dniDos;
this.agenciaCodigo = codagencia;
this.codCobrador = codCobrador;
this.cobDomicilio = cobdom;
this.asesor = ase;
this.cantCuo = cuo;
}
SQL Connection:
public List<Solicitud> cargarDatosPDF(string sol)
{
List<Solicitud> salida = new List<Solicitud>();
string con = "Data Source = dasdasd; Initial Catalog = ProvidusWeb; Persist Security Info = True; User ID = id; Password = pass";
using (SqlConnection conexion = new SqlConnection(con))
{
conexion.Open();
string sql = "SELECT DniNumero, codigo, monto, solicitud, " +
"FechaSolicitud, valnom, DescPlanActual, " +
"apellido, " +
"nombre, " +
"domicilio, numero," +
"piso, dpto, mono, barrio, " +
"acidzona, localidad, provincia, " +
"codigopostal, dnitipo, FechaNacimiento, ocupacion, " +
"telefono, celular, " +
"mail, " +
"EstadoCivil, Observaciones, " +
"NomSegundoSus, DNIsegundoSus, " +
"AgenCob, CodCobrador, " +
"asesor, ancantcuoplan, " +
"CobradorDomicilio " +
" FROM V_SolicitudWeb " +
" WHERE solicitud = #sol ";
SqlCommand cmd = new SqlCommand(sql, conexion);
cmd.Parameters.AddWithValue("#sol", sol);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
try
{
double dni = Convert.ToDouble(dr["dninumero"]?.ToString());
string codigo = dr["codigo"]?.ToString();
decimal? monto = Convert.ToDecimal(dr["monto"]?.ToString());
string soli = dr["solicitud"]?.ToString();
DateTime fechaSolicitud = Convert.ToDateTime(dr["FechaSolicitud"]?.ToString());
double? valnom = Convert.ToDouble(dr["valnom"]?.ToString());
string desc = dr["descplanactual"]?.ToString();
string apellido = dr["apellido"]?.ToString();
string nombre = dr["nombre"]?.ToString();
string domicilio = dr["domicilio"]?.ToString();
string numero = dr["numero"]?.ToString();
string piso = dr["piso"]?.ToString();
string dpto = dr["dpto"]?.ToString();
string mono = dr["mono"]?.ToString();
string barrio = dr["barrio"]?.ToString();
string zona = dr["acidzona"]?.ToString();
string localidad = dr["localidad"]?.ToString();
string provincia = dr["provincia"]?.ToString();
int? cp = Convert.ToInt32(dr["codigopostal"]?.ToString());
string dnitipo = dr["dnitipo"]?.ToString();
string fechaNac = dr["FechaNacimiento"]?.ToString();
string ocupacion = dr["ocupacion"]?.ToString();
string tel = dr["telefono"]?.ToString();
string cel = dr["celular"]?.ToString();
string email = dr["Mail"]?.ToString();
string estadoCivil = dr["EstadoCivil"]?.ToString();
if (estadoCivil == "C")
{
estadoCivil = "Casado";
} else if (estadoCivil == "S")
{
estadoCivil = "Soltero";
}
else if (estadoCivil == "V")
{
estadoCivil = "Viudo";
}
else if (estadoCivil == "D")
{
estadoCivil = "Divorciado";
}
string observaciones = dr["Observaciones"]?.ToString();
string nomDos = dr["NomSegundoSus"]?.ToString();
double dniDos = Convert.ToDouble(dr["DNIsegundoSus"]?.ToString());
string codAgencia = dr["AgenCob"]?.ToString();
string codCobrador = dr["CodCobrador"]?.ToString();
string cobDom = dr["CobradorDomicilio"]?.ToString();
string ase = dr["asesor"]?.ToString();
int cantidadCuotas = Convert.ToInt32(dr["ancantcuoplan"]?.ToString());
Solicitud p = new Solicitud(dni, codigo,monto, soli,
fechaSolicitud, valnom, desc,
apellido,
nombre,
domicilio,numero,
piso, dpto,mono,barrio,
zona,localidad,provincia,
cp,dnitipo, fechaNac, ocupacion,
tel,cel,
email,
estadoCivil, observaciones,
nomDos, dniDos,
codAgencia, codCobrador, codCobrador,
ase, cantidadCuotas);
salida.Add(p);
}
catch (SqlException ex)
{
throw ex;
}
}
conexion.Close();
return salida;
}
}
The error happens on this line of code:
double dniDos = Convert.ToDouble(dr["DNIsegundoSus"]?.ToString());
It is trying to convert something that throws a FormatException. If you are able to do so then do something like this
ISNULL(dr[DNIsegundoSus], 0) as 'DNIsegundoSus'
in your SELECT. If you are unable to do so and need to show a null you might want to return it as a string and let the controller determine to pass 'NULL, blank, '', etc to the view.

I cannot figure out how to fix an unhandled Format Excpetion

I am trying to write a C# program using Visual Studio that reads data from a file and allow me perform various sorts on the data. I am a beginner so it took much research to figure out how to write this code: Now I get a:
Format Exception was unhandled. Input string was not in a correct
format
I am not sure where I went wrong. This is happening for the following line of code:
Candidate newrec = new Candidate(str[0], str[1], str [2], str[3], str[4], str[5], str[6], Convert.ToInt32(str[7]), str[8], str[9], str[10], str[11]);
The entire code is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Collections;
namespace Unit4IP
{
//used to sort in asceding and descending order
public struct Candidate:IComparable
{
public char[] _FirstName;
public char[] _LastName;
public char[] _Company;
public char[] _Address;
public char[] _City;
public char[] _Country;
public char[] _State;
public char[] _Phone;
public char[] _Fax;
public char[] _Email;
public char[] _Web;
public int _zip;
//for comparing objects
public int CompareTo(object obj)
{
Candidate Candidate2 = (Candidate)obj;
return _LastName.ToString().CompareTo(Candidate2._LastName.ToString());
}
//implements sorting based on assignments such as zip, lastname, etc.
public int CompareTo(Candidate Candidate2,
CandidateComparer.ComparisonType comptype)
{
if(comptype==CandidateComparer.ComparisonType.Lastname)
{
String _LName = new String(_LastName);
String LName = new String(Candidate2._LastName);
return _LName.CompareTo(LName);// Convert Character Array to String because CompareTo Works efficiently with Strings
}
else
{
return Candidate2._zip.CompareTo(_zip); // compareto values that are interchanged in descending order
}
}
//Constructor of Candidate Structure
public Candidate(string FirstName, string LastName, string Company, string Address, string City, string Country, string State, int zip, string Phone, string Fax, string Email, string Web)
{
_FirstName = new char[12];
_LastName = new char[16];
_Company = new char[32];
_Address = new char[32];
_City = new char[24];
_Country = new char[24];
_State = new char[2];
_Phone = new char[12];
_Fax = new char[12];
_Email = new char[32];
_Web = new char[42];
_FirstName = FirstName.ToCharArray();
_LastName = LastName.ToCharArray();
_Company = Company.ToCharArray();
_Address = Address.ToCharArray();
_City = City.ToCharArray();
_Country = Country.ToCharArray();
_State = State.ToCharArray();
_zip = zip;
_Phone = Phone.ToCharArray();
_Fax = Fax.ToCharArray();
_Email = Email.ToCharArray();
_Web = Web.ToCharArray();
}
//Implement IComparer Interface as nested structure
public struct CandidateComparer : IComparer
{
public enum ComparisonType
{ Lastname = 1, zip = 2 }
private ComparisonType _comparisonType;
public ComparisonType comptype
{
get { return _comparisonType; }
set { _comparisonType = value; }
}
public int Compare(object x, object y)
{
Candidate Candidate1 = (Candidate)x;
Candidate Candidate2 = (Candidate)y;
return Candidate1.CompareTo(Candidate2, _comparisonType);
}
}
}
class Program
{
static void Main(string[] args)
{
ArrayList ArrayTest = new ArrayList();
//Loading of File 'ITCO321_U4_sample_data.csv' into ArraList. File only holds values, no heading i.e. remove headings
StreamReader stream1 = File.OpenText("c:\\Users\\Cdhss\\Documents\\ITCO321_U4IP_sample_data-2.csv");
string recdata = null;
while ((recdata = stream1.ReadLine()) != null)
{
string[] str = recdata.Split(',');
Candidate newrec = new Candidate(str[0], str[1], str [2], str[3], str[4], str[5], str[6], Convert.ToInt32(str[7]), str[8], str[9], str[10], str[11]);
ArrayTest.Add(newrec);//add struct object into ArrayList
}
//Traversing of Records
Console.WriteLine("Traversing Records");
foreach (Candidate Candidate1 in ArrayTest)
{
string fname = new String(Candidate1._FirstName);
string lname=new String(Candidate1._LastName);
string company = new String(Candidate1._Company);
string address=new String(Candidate1._Address);
string city=new String(Candidate1._City);
string country = new String(Candidate1._Country);
string phone = new String(Candidate1._Phone);
string fax = new String(Candidate1._Fax);
string email=new String(Candidate1._Email);
string web = new String(Candidate1._Web);
Console.WriteLine( fname + "," + lname + "," + company + "," + address + "," + city + "," + country + "," + Candidate1._zip + "," + phone + "," + fax + "," + email + "," + web);
}
Candidate.CandidateComparer comparer = new Candidate.CandidateComparer();
//Sort by Lastname in ascending order
comparer.comptype = Candidate.CandidateComparer.ComparisonType.Lastname;
ArrayTest.Sort(comparer);
Console.WriteLine("Sorting of Elements by LastName");
foreach (Candidate Candidate1 in ArrayTest)
{
string fname = new String(Candidate1._FirstName);
string lname = new String(Candidate1._LastName);
string company = new String(Candidate1._Company);
Console.WriteLine("\t" + fname + "," + lname + "," + company);
}
// Data sorted in desending order of ZIP field
comparer.comptype = Candidate.CandidateComparer.ComparisonType.zip;
ArrayTest.Sort(comparer);
Console.WriteLine("Sorting of Elements by Zip");
foreach (Candidate Candidate1 in ArrayTest)
{
string fname = new String(Candidate1._FirstName);
string lname = new String(Candidate1._LastName);
string company = new String(Candidate1._Company);
Console.WriteLine("\t" + fname + "," + lname + "," + company + "," + Candidate1._zip);
}
//Display Records of 'NY' State
Console.WriteLine("Display Records of NY State");
foreach (Candidate Candidate1 in ArrayTest)
{
string fname = new String(Candidate1._FirstName);
string lname = new String(Candidate1._LastName);
string company = new String(Candidate1._Company);
string address = new String(Candidate1._Address);
string city = new String(Candidate1._City);
string country = new String(Candidate1._Country);
string phone = new String(Candidate1._Phone);
string fax = new String(Candidate1._Fax);
string email = new String(Candidate1._Email);
string web = new String(Candidate1._Web);
if (new String(Candidate1._State).Contains("NY"))
Console.WriteLine(fname + "," + lname + "," + company + "," + address + "," + city + "," + country + "," + Candidate1._zip + "," + phone + "," + fax + "," + email + "," + web);
}
Console.Read();
}
}
}
Your problem is in your call to Convert.ToInt32. Whatever string you are passing can't be parsed as an int.
A good solution here might be to use the some structured exception handling, either with try catch blocks or Int32.TryParse(string) for example you could do this
int intValue;
if (Int32.TryParse(str[7], out intValue))
{
//Do some thing with the int value
}
else
{
throw new Exception("Some informative error message, probably using string.Format to include the string you tried to parse");
}
TryParse returns true if the parse is successfull, false if it is not, and puts the parsed integer value in the second out parameter.
A few other comments on you code to help you out.
No one uses ArrayLists in C# anymore. Generics were introduced a long time ago, and it is almost always better, from a standpoint of both type safety and speed to use a List (Look up C# generics if you don't know what they are).
You don't need to copy the candidate properties in your foreach loop into new variables.
Give more informative variable names. Readability is the single most important quality in good code. fname should be firstName, recdata should be recievedData. Key strokes are cheap in a world with tab completion.

The place for the first record is empty in RDLC report

I have made a 2-column report that is like this :
Name1----------------------------Name3
Address1-------------------------Address3
Name2----------------------------Name4
Address2-------------------------Address4
But suddenly it started to give reports like this :
----------------------------Name3
-------------------------Address3
Name1----------------------------Name4
Address1-------------------------Address4
Name2
Address2
Here is my code :
public ActionResult Report()
{
LocalReport lr = new LocalReport();
string path = Path.Combine(Server.MapPath("~/Report"), "Person.rdlc");
if (System.IO.File.Exists(path))
{
lr.ReportPath = path;
}
else
{
return View("Index");
}
List<Person> cm = new List<Person>();
var viewModel = new PersonIndexData();
viewModel.People = db.Person
.Include(k => k.Groups)
.OrderBy(k => k.Name);
cm = viewModel.People.ToList();
ReportDataSource rd = new ReportDataSource("DataSet1", cm);
lr.DataSources.Add(rd);
string reportType = "pdf";
string mimeType = string.Empty;
string encoding = string.Empty;
string fileNameExtension = string.Empty;
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>pdf</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>12in</PageHeight>" +
" <MarginTop>0.5in</MarginTop>" +
" <MarginLeft>0.5in</MarginLeft>" +
" <MarginRight>1in</MarginRight>" +
" <MarginBottom>0.2in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
renderedBytes = lr.Render(
"pdf",
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
return File(renderedBytes, mimeType);
}
Namely the place for the first record is empty. Why do you think it happened and how I can get rid of it? I changed column spacing and margins but it didn't work. Thanks.
You cannot fetch the first column value from a table. That's the reason it cannot display the first column value.

Twitter home_timeline Windows 8 C# call returns Could not authenticate you

I'm trying to pull the timeline of an authenticated user in a Windows 8.1/Windows Phone 8.1 Universal app. I believe I have everything set up correctly, but I keep getting a response of "code=32, message=Could not authenticate you" in Fiddler.
I think I'm just using the headers in the TwitterGetRequest function wrong, but I can't figure out the exact issue.
This is all based off the WebAuthentication Sample code from MSDN.
Here's the main function
private async Task GetTwitterUserNameAsync(string webAuthResultResponseData)
{
//
// Acquiring a access_token first
//
string responseData = webAuthResultResponseData.Substring(webAuthResultResponseData.IndexOf("oauth_token"));
string request_token = null;
string oauth_verifier = null;
String[] keyValPairs = responseData.Split('&');
for (int i = 0; i < keyValPairs.Length; i++)
{
String[] splits = keyValPairs[i].Split('=');
switch (splits[0])
{
case "oauth_token":
request_token = splits[1];
break;
case "oauth_verifier":
oauth_verifier = splits[1];
break;
}
}
String TwitterUrl = "https://api.twitter.com/oauth/access_token";
string response = await TwitterPostRequest(request_token, oauth_verifier, TwitterUrl);
String[] Tokens = response.Split('&');
string oauth_token_secret = null;
string access_token = null;
string screen_name = null;
for (int i = 0; i < Tokens.Length; i++)
{
String[] splits = Tokens[i].Split('=');
switch (splits[0])
{
case "screen_name":
screen_name = splits[1];
break;
case "oauth_token":
access_token = splits[1];
break;
case "oauth_token_secret":
oauth_token_secret = splits[1];
break;
}
}
//you can store access_token and oauth_token_secret for further use. See Scenario5(Account Management).
if (access_token != null)
{
DebugPrint("access_token = " + access_token);
}
if (oauth_token_secret != null)
{
DebugPrint("oauth_token_secret = " + oauth_token_secret);
}
if (screen_name != null)
{
//rootPage.NotifyUser(screen_name + " is connected!!", NotifyType.StatusMessage);
}
string timeline = await TwitterGetRequest(access_token, oauth_token_secret, oauth_verifier, "https://api.twitter.com/1.1/statuses/home_timeline.json");
List<SocialItem> tweets = new List<SocialItem>();
if (timeline.Length > 0)
{
JArray tweetArray = JArray.Parse(timeline);
for(int i=0;i<tweetArray.Count();i++)
{
JObject tweet = JObject.Parse(tweetArray[i].ToString());
JObject tweetAuthor = JObject.Parse(tweet["user"].ToString());
string imgUrl = tweetAuthor["profile_image_url"].ToString();
string message = tweet["text"].ToString();
string userName = tweetAuthor["screen_name"].ToString();
string displayName = tweetAuthor["name"].ToString();
string createdAtString = tweet["created_at"].ToString();
DateTime created;
if(!DateTime.TryParse(createdAtString, out created))
{
created = DateTime.MinValue;
}
tweets.Add(new SocialItem
{
ImageUrl = imgUrl,
MessageBody = message,
UserName = userName,
DisplayName = displayName,
MessageDate = created,
ProfileUrl = ("http://twitter.com/" + userName)
});
}
this.DataContext = tweets;
}
}
Here's the supporting functions:
private async Task<string> TwitterPostRequest(string request_token, string oauth_verifier, String TwitterUrl)
{
string timeStamp = GetTimeStamp();
string nonce = GetNonce();
String SigBaseStringParams = "oauth_consumer_key=" + Twitter.CLIENT_ID;
SigBaseStringParams += "&" + "oauth_nonce=" + nonce;
SigBaseStringParams += "&" + "oauth_signature_method=HMAC-SHA1";
SigBaseStringParams += "&" + "oauth_timestamp=" + timeStamp;
SigBaseStringParams += "&" + "oauth_token=" + request_token;
SigBaseStringParams += "&" + "oauth_version=1.0";
String SigBaseString = "POST&";
SigBaseString += Uri.EscapeDataString(TwitterUrl) + "&" + Uri.EscapeDataString(SigBaseStringParams);
String Signature = GetSignature(SigBaseString, Twitter.CLIENT_SECRET);
HttpStringContent httpContent = new HttpStringContent("oauth_verifier=" + oauth_verifier, Windows.Storage.Streams.UnicodeEncoding.Utf8);
httpContent.Headers.ContentType = HttpMediaTypeHeaderValue.Parse("application/x-www-form-urlencoded");
string authorizationHeaderParams = "oauth_consumer_key=\"" + Twitter.CLIENT_ID + "\", oauth_nonce=\"" + nonce + "\", oauth_signature_method=\"HMAC-SHA1\", oauth_signature=\"" + Uri.EscapeDataString(Signature) + "\", oauth_timestamp=\"" + timeStamp + "\", oauth_token=\"" + Uri.EscapeDataString(request_token) + "\", oauth_version=\"1.0\"";
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new HttpCredentialsHeaderValue("OAuth", authorizationHeaderParams);
var httpResponseMessage = await httpClient.PostAsync(new Uri(TwitterUrl), httpContent);
string response = await httpResponseMessage.Content.ReadAsStringAsync();
return response;
}
private async Task<string> TwitterGetRequest(string request_token, string oauth_token_secret, string oauth_verifier, String TwitterUrl)
{
string timeStamp = GetTimeStamp();
string nonce = GetNonce();
String SigBaseStringParams = "oauth_consumer_key=" + Twitter.CLIENT_ID;
SigBaseStringParams += "&" + "oauth_nonce=" + nonce;
SigBaseStringParams += "&" + "oauth_signature_method=HMAC-SHA1";
SigBaseStringParams += "&" + "oauth_timestamp=" + timeStamp;
SigBaseStringParams += "&" + "oauth_token=" + request_token;
SigBaseStringParams += "&" + "oauth_version=1.0";
String SigBaseString = "GET&";
SigBaseString += Uri.EscapeDataString(TwitterUrl) + "&" + Uri.EscapeDataString(SigBaseStringParams);
String Signature = GetSignature(SigBaseString, oauth_token_secret);
//HttpStringContent httpContent = new HttpStringContent("oauth_verifier=" + oauth_verifier, Windows.Storage.Streams.UnicodeEncoding.Utf8);
//httpContent.Headers.ContentType = HttpMediaTypeHeaderValue.Parse("application/x-www-form-urlencoded");
string authorizationHeaderParams = "oauth_consumer_key=\"" + Twitter.CLIENT_ID +
"\", oauth_nonce=\"" + nonce +
"\", oauth_signature_method=\"HMAC-SHA1\", oauth_signature=\"" + Uri.EscapeDataString(Signature) +
"\", oauth_timestamp=\"" + timeStamp +
"\", oauth_token=\"" + Uri.EscapeDataString(request_token) +
"\", oauth_version=\"1.0\"";
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new HttpCredentialsHeaderValue("OAuth", authorizationHeaderParams);
string response="";
try
{
response = await httpClient.GetStringAsync(new Uri(TwitterUrl));//httpClient.PostAsync(new Uri(TwitterUrl), httpContent);
}
catch (Exception ex)
{
DebugPrint(ex.Message);
}
//string response = await httpResponseMessage.Content.ReadAsStringAsync();
return response;
}
string GetNonce()
{
Random rand = new Random();
int nonce = rand.Next(1000000000);
return nonce.ToString();
}
string GetTimeStamp()
{
TimeSpan SinceEpoch = DateTime.UtcNow - new DateTime(1970, 1, 1);
return Math.Round(SinceEpoch.TotalSeconds).ToString();
}
string GetSignature(string sigBaseString, string consumerSecretKey)
{
IBuffer KeyMaterial = CryptographicBuffer.ConvertStringToBinary(consumerSecretKey + "&", BinaryStringEncoding.Utf8);
MacAlgorithmProvider HmacSha1Provider = MacAlgorithmProvider.OpenAlgorithm("HMAC_SHA1");
CryptographicKey MacKey = HmacSha1Provider.CreateKey(KeyMaterial);
IBuffer DataToBeSigned = CryptographicBuffer.ConvertStringToBinary(sigBaseString, BinaryStringEncoding.Utf8);
IBuffer SignatureBuffer = CryptographicEngine.Sign(MacKey, DataToBeSigned);
string Signature = CryptographicBuffer.EncodeToBase64String(SignatureBuffer);
return Signature;
}
I have never received this kind of error but I have been developing with Tweetinvi and it is very easy to retrieve the timeline of the authenticated user.
Just do the following:
TwitterCredentials.SetCredentials("ACCESS_TOKEN", "ACCESS_TOKEN_SECRET", "CONSUMER_KEY", "CONSUMER_SECRET");
var tweets = Timeline.GetHomeTimeline();
Hope this helps.

retrieve username and nickname from active directory on local network

I want to read the username and NickName of any users on my local network from server's active directory. How can I do it? Thanks alot.
public void getUser()
{
DirectoryServices.SearchResult myResult;
string filterString = string.Empty;
string EntryString = "LDAP:// <Your AD Domain here>";
DirectoryServices.DirectorySearcher myDirectorySearcher = new DirectoryServices.DirectorySearcher(new DirectoryServices.DirectoryEntry(EntryString, "Username", "Password"));
string tempStr;
string[] splStr = new string[3];
filterString = "(sAMAccountName=" + Username + ")";
myDirectorySearcher.Filter = filterString;
myDirectorySearcher.PropertiesToLoad.Add("cn");
myResult = myDirectorySearcher.FindOne();
splStr = Regex.Split(myResult.Properties("cn").Item(0).ToString, " ");
tempStr = splStr(1).ToString + " " + splStr(0).ToString;
Label1.Text = "Hello " + tempStr;
}

Categories

Resources