using (WebClient client = new WebClient())
{
byte[] ByteStream = ConvertFileIntoBtes("c:\\test.jpg");
if (ByteStream != null)
{
client.Credentials = new System.Net.NetworkCredential(USERNAME, PASSWORD);
client.UploadData(FTPSERVER + "/test.jpg", "STOR", ByteStream);
}
}
Wednesday, August 14, 2013
Upload file into FTP
this is example code for upload file into FTP site.
Labels:
Examples - C# WinForm,
Lessons - C# basics
Function for Resize Image
this is a function that resizes the image into given size.
private static Image resizeImage(Image imgToResize, Size size)
{
int sourceWidth = imgToResize.Width;
int sourceHeight = imgToResize.Height;
float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)size.Width / (float)sourceWidth);
nPercentH = ((float)size.Height / (float)sourceHeight);
if (nPercentH < nPercentW)
nPercent = nPercentH;
else
nPercent = nPercentW;
int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);
Bitmap b = new Bitmap(destWidth, destHeight);
Graphics g = Graphics.FromImage((Image)b);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
g.Dispose();
return (Image)b;
}
Labels:
Examples - C# WinForm,
Lessons - C# basics
Connection strings for MS Access and MS Excel in C#
Connecttion strings for
MS ACCESS
- OleDbConnection connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=electiondb.accdb;Persist Security Info=False;");
EXCEL
OleDbConnection connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=election.xlsx;Extended Properties='Excel 8.0;HDR=NO;IMEX=1';");
MS ACCESS
- OleDbConnection connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=electiondb.accdb;Persist Security Info=False;");
EXCEL
OleDbConnection connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=election.xlsx;Extended Properties='Excel 8.0;HDR=NO;IMEX=1';");
Subscribe to:
Comments (Atom)
