Skip to main content

Posts

Showing posts with the label C#

How to Check Local Machine Name and IP Address Using C#

How to check client Machine or local Machine Name and IP address using C-sharp, See the below simple example code. CODE: 1 : using System.Net; 2 : 3 : string hostName = Dns.GetHostName(); 4 : IPHostEntry ie = Dns.GetHostByName(hostName); 5 : IPAddress[] ia= ie.AddressList; 6 : 7 : MessageBox.Show("Local Machine Name : "+hostName.ToString()); 8 : MessageBox.Show("IP address Of Local Machine "+ipAddress[0].ToString());

How to Check Internet Connection Using C-Sharp

How to check internet connection using c#? Here is a simple example to find out internet connection or page response using c -Sharp CODE: 1 : Using System.Net ; 2 : try{ 3 : HttpWebRequest request= (HttpWebRequest) HttpWebRequest.Create("google.com"); 4 : HttpWebResponse response= (HttpWebResponse) request.GetResponse(); 5 : if (HttpStatusCode.OK == response.StatusCode) 6 : { 7 : //Write here your code... 8 : response.Close(); 9 : } 10 : }catch (Exception ex){ 11 : MessageBox.Show("Unable to connect"); 12 : }

C Sharp User Define SQL Database Class

This is the simple user define SQL Database Class. It is useful to avoid redundancy of the code. Database Class In C# using System; using System.Data; using System.Data.SqlClient; using System.Configuration; public class _Database { public SqlConnection con; public SqlCommand com = null; public SqlDataReader dr = null; public SqlDataAdapter da = null; public DataSet ds = null; public String glQuery = ""; public String glnonQuery = ""; public const int EXECUTE_NONE_QUERY = 1; public const int EXECUTE_QUERY = 2; public const int DATA_ADAPTER = 3; // connection for data list paging public SqlConnection globalcon = new SqlConnection("server=**;uid=**;pwd=***;Database=**"); public _Database() { } public void Query(String SqlQuery) { this.glQuery = this.Get_DataBasePrefix(SqlQuery); } private String Get_DataBasePrefix(String str) { return str.Replace("#__", "GD_").ToString(); } public void ConnectDB() { try { con = new SqlConnection(); con.Co...

FTP File Uploading Using C Sharp

This is the example to upload file using FTP Web Request. using system.net; using system.io; FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("ftp://myDoc.com/xyz.pdf"); / request.Method = WebRequestMethods.Ftp.UploadFile; request.Credentials = new NetworkCredential(username, password); request.UsePassive = true; request.UseBinary = true; request.KeepAlive = false; //Load the file FileStream stream = File.OpenRead(filePath); //c:/myDoc/xyz.pdf byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); stream.Close(); //Upload file Stream reqStream = request.GetRequestStream(); reqStream.Write(buffer, 0, buffer.Length); reqStream.Close(); btnUpload.UseWaitCursor = false;

Convert Image Into Jpeg Using C sharp.

This example is useful to upload image of any format and Convert into JPEG or JPG Using C-Sharp. using System.IO; using System.Drawing; using System.Drawing.Imaging; using System.Reflection; using System.Drawing.Drawing2D; public class _Library { public string w; public string h; public _Library() { } /* for uploading Image */ public String UploadFile(FileUpload Fileobject,String Path) { String FileName = ""; String[] getformat; String imgformat1 = "", imgformat2 = ""; if (Fileobject.HasFile) { FileName = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + "_" + Fileobject.FileName.Replace(' ','-').ToLower(); Fileobject.SaveAs(@"" + Path + "" + FileName); getformat =FileName.ToString().Split('.'); imgformat1 = getformat[0].ToString(); imgformat2 = getformat[1].ToStrin...