Thursday, June 18, 2015

Send Mail Using SMTP,With UserName- Password ,#C

 private string SendEmailSMTP(string EmailId, string Subject, string MessageBody)
    {
        string Confirmation = string.Empty;
        try
        {

            string Subject = Subject; //----Subject of the Mail
            string MessageBody = "MessageBody"//--Your Message Body Text Goes Here";
         
            MailMessage Mail = new MailMessage();
            MailAddress fromAddress = new MailAddress("FromAddress@someexample.Com");
         
            Mail.From = fromAddress;
            Mail.To.Add(EmailId);//-----To Mail Address
            Mail.Subject = Subject;
            Mail.Body = MessageBody;
            SmtpClient SmtpServer = new SmtpClient();
            SmtpServer.Host = "00.00.0.000"; //---Host Address Goes Here
         
            SmtpServer.Port = 25;
            SmtpServer.Credentials = new NetworkCredential("YourUserName", "YourPassword");
            Mail.IsBodyHtml = true;        
            SmtpServer.Send(Mail);
            Confirmation = "1";
        }
        catch
        {
            Confirmation = "0";
        }
        return Confirmation;
    }

Sending Rest API Request from C#

public Object FTRJMSRequest(string RequestType, string Type, string SubType, string SubSubType, string QRCType, string FaultFound, string ResolutionType, string Mobile)
 {
 const string URL = "http://00.00.000.00:8080/knowmaxservice/webresources/webservice/SendRequest/";

 string DATA = "{'RequestType':'" + RequestType + "','Type':'" + Type + "','SubType':'" + SubType + "','SubSubType':'" + SubSubType + "','QRCType':'" + QRCType + "','FaultCode':'" + FaultFound + "','ResolutionCode':'" + ResolutionType + "','Mobile':'" + Mobile + "','Notes':'Testing in Progress....','UserName':'Service_Setup'}";

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
 request.Method = "POST";
 request.ContentType = "application/json";
 request.ContentLength = DATA.Length;
 using (Stream webStream = request.GetRequestStream())
 using (StreamWriter requestWriter = new StreamWriter(webStream, System.Text.Encoding.ASCII)) {
 requestWriter.Write(DATA);
 }
 try {
 WebResponse webResponse = request.GetResponse();
 using (Stream webStream = webResponse.GetResponseStream())
 {
 if (webStream != null) {
 using (StreamReader responseReader = new StreamReader(webStream))
 {
           string response = responseReader.ReadToEnd();
                    objReturn = response.ToString();
 //Console.Out.WriteLine(response.ToString());
 }
 }
}
}
 catch (Exception e)
 {
 //Console.Out.WriteLine("-----------------");
 //Console.Out.WriteLine(e.Message);
 }
 return objReturn;
}

Wednesday, November 30, 2011

Find usercontrol method in web page

 System.Web.UI.HtmlControls.HtmlTable tbl = (System.Web.UI.HtmlControls.HtmlTable)ctrlStorage.FindControl("CalnderDiv");

Wednesday, August 17, 2011

How to make button Default button when hit enter key

// Button1 is the ID of button.
// form1 is the ID of form tag which is in master page.

(Page.Master.FindControl("form1") as HtmlForm).DefaultButton = this.Button1.UniqueID;


Wednesday, July 27, 2011

Set AutoIncrement to "0"


USE NopNew;
  GO
  DBCC CHECKIDENT ("Nop_Picture", RESEED, 0);
  GO

//nopnew is the database name
// nop_picture is the table name

Friday, July 1, 2011

How to Store .CSV file in Sql Server


CREATE TABLE CSVTestNewTest
(
[Offer Ref] Nvarchar (255),
[Quote Ref] Nvarchar(100),
[Midwich Part] Nvarchar(200),
[Midwich Part Description] Nvarchar(200),
[Minimum] nvarchar(50),
[Qty] nvarchar(200),
[Free Part Description] nvarchar(max),
[Offer Description] nvarchar(max),
[Type] nvarchar(100),
[Available Qty] nvarchar(200)
)
GO

BULK
INSERT CSVTestNewTest
FROM 'D:\varun\Project Assets\Qb Assets\Qb Assets\Data Feed 30june11\data\free_parts.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO



Description: first of all create table of all the column available in excel or csv file. then with the bulk insert statement give the location where your excel or csv file is stored and exceute the query with syntax describe above.