Friday, 3 of July of 2009

News

How to upload file using C# code

First you have to create FTP request

FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(FTPAddress + “/” + Path.GetFileName(filePath));

request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(username, password);
request.UsePassive = false;
request.UseBinary = true;
request.KeepAlive = false;

Then load the file

FileStream stream = File.OpenRead(filePath);
byte[] buffer = new byte[stream.Length];

stream.Read(buffer, 0, buffer.Length);
stream.Close();

Upload the file

Stream reqStream = request.GetRequestStream();
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Close();


1 comment

How to get your ISP IP address in ASP.Net C#

Using the http://www.whatismyip.com website and System.Net.WebClient(), you can get your ISP IP address.

Here’s what it look like in the code:

string ip = new System.Net.WebClient().DownloadString((”http://www.whatismyip.com/automation/n09230945.asp”));
Console.WriteLine(”My IP address is ” + _ip);


Do your comment

How to create popup message box using javascript in ASP.Net C#

Generate a popup message using javascript alert function then dumped it into a label with the string argument passed in to supply the alert box text.

Label lbl = new Label();
lbl.Text =”<script language=”javascript”> window.alert(” + “‘” + msg + “‘” + “)</script>”; 

Then add the label to the page to display the alert

Page.Controls.Add(lbl);

Here’s what it looks like:

private void MessageBox(string msg) {
Label lbl = new Label();
lbl.Text = “<script language=”javascript”> window.alert(” + “‘” + msg + “‘” + “)</script>”;
Page.Controls.Add(lbl);
}


4 comments

How to create Captcha in ASP.NET VB

captchaVB

CaptchaVB.NET
This is originally created in C#, and I converted it to  ASP.NET VB. Enjoy!!!

Download CaptchaVB.NET here


Do your comment

ImageGallery.NET

imageGallery ImageGallery.Net
ImageGallery.Net Features multiple uploads,
image viewer using greybox ajax framework,
Subsonic for DAL(Data Access Layer).

Created in ASP.NET/C# 3.5 Framework


Download ImageGallery.Net here.


Do your comment

How to Create XML in ASP.NET 3.5

This is very easy and sufficient way in building XML data.

Using the System.XML.Linq in .NET 3.5 makes building xml data extremely easy.

Here’s what it looks like in the code:

XElement doc = new XElement("movie",
new XElement("styles",
new XElement("lineStyle",
new XAttribute("id", "lineBlack"),
new XAttribute("color", "#000000"),
new XAttribute("width","1"))
)
);

will give you the following xml:

<movie>
<styles>
<lineStyle id=”lineBlack” color=”#000000″ width=”1″ />
</styles>
</movie>


1 comment