Click here to Skip to main content
15,891,951 members
Home / Discussions / C#
   

C#

 
GeneralRe: Repost Pin
Abhinav S31-Oct-10 23:47
Abhinav S31-Oct-10 23:47 
AnswerRe: Add control to form ,from UserControl Pin
Shuaib wasif khan1-Nov-10 1:50
Shuaib wasif khan1-Nov-10 1:50 
GeneralRe: Add control to form ,from UserControl Pin
Said Ali Jalali2-Nov-10 23:53
Said Ali Jalali2-Nov-10 23:53 
QuestionHow to use Get Post in C# Pin
Sonu J30-Oct-10 20:38
Sonu J30-Oct-10 20:38 
AnswerRe: How to use Get Post in C# Pin
Abhinav S31-Oct-10 0:02
Abhinav S31-Oct-10 0:02 
AnswerRe: How to use Get Post in C# Pin
Eddy Vluggen31-Oct-10 0:05
professionalEddy Vluggen31-Oct-10 0:05 
AnswerRe: How to use Get Post in C# Pin
Ravi Bhavnani31-Oct-10 16:33
professionalRavi Bhavnani31-Oct-10 16:33 
AnswerRe: How to use Get Post in C# Pin
VarunSharma432-Nov-10 20:44
professionalVarunSharma432-Nov-10 20:44 
#region HttpPost
protected string HttpPost(string url_, string contents_, bool useCredentials_, NetworkCredential creds_)
{
bool isSuccess = false;
int noOfRetry = 0;
string response = string.Empty;
try
{
WriteToLog(string.Format("Starting HTTPPost Publishing message {0} \r\n {1}", url_, contents_));

while (!isSuccess && noOfRetry < m_noOfRetry)
{
WriteToLog("HTTPPost " + "Success Status :" + isSuccess.ToString() + " Retry Count: " + noOfRetry.ToString());
Uri url = new Uri(url_);
HttpWebRequest _webRequest = (HttpWebRequest)WebRequest.Create(url);
_webRequest.Timeout = 400000000;
_webRequest.Method = "POST";
_webRequest.ContentType = "text/xml; charset=ISO-8859-1";
_webRequest.KeepAlive = true;
_webRequest.Credentials = CredentialCache.DefaultNetworkCredentials;

if (useCredentials_)
{
string password = string.Empty;
string username = string.Empty;

//if no credentails provided then use
if (creds_ == null)
{
password = ConfigurationManager.AppSettings["password"] == null ?
null : ConfigurationManager.AppSettings["password"].ToString();

username = ConfigurationManager.AppSettings["user"] == null ?
null : ConfigurationManager.AppSettings["user"].ToString();

if (password == null || username == null)
{
WriteToLog(SMSConstants.INCOMPLETE_SMSGATEWAY_INFORMATION);
throw new Exception(SMSConstants.INCOMPLETE_SMSGATEWAY_INFORMATION);
}
WriteToLog("Connecting using UserName :" + username);

password = GetDecString(password);

String userInfo = username + ":" + password;
byte[] bt = new byte[userInfo.Length];
bt = System.Text.Encoding.UTF8.GetBytes(userInfo);
string encodedData = Convert.ToBase64String(bt);
String authInfo = "Basic " + encodedData;
_webRequest.Headers.Set("Authorization", authInfo);
}
else
{
_webRequest.Credentials = creds_;
WriteToLog(String.Format("{0}{1}", "Connecting using provided User credentials UserName :", creds_.UserName));
}
}

try
{
Stream _stream = _webRequest.GetRequestStream();
StreamWriter _writer = new StreamWriter(_stream);
_writer.Write(contents_);
_writer.Close();

HttpWebResponse _webResponse = (HttpWebResponse)_webRequest.GetResponse();
_stream = _webResponse.GetResponseStream();
StreamReader _sReader = new StreamReader(_stream);
String _response = _sReader.ReadToEnd();

_sReader.Close();
response = _response;

//Underlying connection closed response NOT An EXCEPTION
if (response.IndexOf("The underlying connection was closed:") == -1)
{
isSuccess = true;
}
else
{
isSuccess = false;
Thread.Sleep(1000);
}
}
//Got exception for connection closed
catch (Exception exp_)
{
if (exp_.Message.IndexOf("The underlying connection was closed:") != -1)
{
WriteToLog(string.Format("The underlying connection was closed. retrying {0}", noOfRetry.ToString()), EventLogEntryType.Error);
isSuccess = false;
}
}
noOfRetry++;
}
WriteToLog("HTTPPost Published message successfully");
}
catch (Exception exp_)
{
response = exp_.Message + Environment.NewLine + exp_.StackTrace;
WriteToLog(string.Format("In Catch Block {0}", response), EventLogEntryType.Error);
}
return response;
}
#endregion //End-HttpPost
#region WriteToLog
/// <summary>
/// Writes a message to Event Log
/// </summary>
/// <param name="message_">message to log</param>
protected void WriteToLog(string message_)
{
WriteToLog(message_, EventLogEntryType.Information);
}
#endregion //End-WriteToLog

#region WriteToLog
/// <summary>
/// Writes a message to Event Log
/// </summary>
/// <param name="message_">message to log</param>
/// <param name="level_">Level to Log error</param>
protected void WriteToLog(string message_, EventLogEntryType level_)
{
try
{
object logConfig = ConfigurationManager.AppSettings["enablelogging"];
bool enableLogging = logConfig == null ? false : Convert.ToBoolean(logConfig.ToString());

Console.WriteLine(Environment.NewLine + message_);

if (enableLogging)
{
string CurrentDate = DateTime.Now.ToShortDateString().Replace("/", "-");

File.AppendAllText(Server.MapPath("Logs/Error_Log_" + CurrentDate),
string.Format("{0}{1} {2} {3}"
, Environment.NewLine
, CurrentDate
, DateTime.Now.ToLongTimeString()
, message_));
}
}
catch //(Exception exp_)
{
//throw exp_;
}

}
#endregion //End-WriteToLog
cheers
varun sharma

QuestionPopulate c# datastructure from table or view [modified] Pin
Michael Pauli30-Oct-10 14:48
Michael Pauli30-Oct-10 14:48 
AnswerRe: Populate c# datastructure from table or view Pin
Karthik. A30-Oct-10 15:59
Karthik. A30-Oct-10 15:59 
QuestionResizing form according to the screen resolution Pin
Nouman Bhatti29-Oct-10 22:03
Nouman Bhatti29-Oct-10 22:03 
AnswerRe: Resizing form according to the screen resolution Pin
OriginalGriff29-Oct-10 22:31
mveOriginalGriff29-Oct-10 22:31 
GeneralRe: Resizing form according to the screen resolution Pin
Michael Pauli30-Oct-10 14:55
Michael Pauli30-Oct-10 14:55 
GeneralRe: Resizing form according to the screen resolution Pin
OriginalGriff30-Oct-10 20:53
mveOriginalGriff30-Oct-10 20:53 
AnswerRe: Resizing form according to the screen resolution Pin
Eddy Vluggen31-Oct-10 0:14
professionalEddy Vluggen31-Oct-10 0:14 
AnswerRe: Resizing form according to the screen resolution Pin
fjdiewornncalwe31-Oct-10 9:40
professionalfjdiewornncalwe31-Oct-10 9:40 
Questiondatagridview KeyDown event doesnt working Pin
Erdinc2729-Oct-10 21:45
Erdinc2729-Oct-10 21:45 
AnswerRe: datagridview KeyDown event doesnt working Pin
Richard MacCutchan29-Oct-10 22:45
mveRichard MacCutchan29-Oct-10 22:45 
GeneralRe: datagridview KeyDown event doesnt working Pin
Erdinc2730-Oct-10 1:14
Erdinc2730-Oct-10 1:14 
GeneralRe: datagridview KeyDown event doesnt working Pin
Dave Kreskowiak30-Oct-10 9:02
mveDave Kreskowiak30-Oct-10 9:02 
GeneralRe: datagridview KeyDown event doesnt working Pin
Richard MacCutchan30-Oct-10 9:28
mveRichard MacCutchan30-Oct-10 9:28 
AnswerRe: datagridview KeyDown event doesnt working Pin
Michael Pauli30-Oct-10 15:14
Michael Pauli30-Oct-10 15:14 
GeneralRe: datagridview KeyDown event doesnt working Pin
Erdinc273-Nov-10 0:24
Erdinc273-Nov-10 0:24 
Questionproblem related to "Nural networks face detection algprithm" Pin
inayathussaintoori29-Oct-10 15:07
inayathussaintoori29-Oct-10 15:07 
AnswerNural networks Repost Pin
Richard MacCutchan29-Oct-10 22:34
mveRichard MacCutchan29-Oct-10 22:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.