SIGN UP MEMBER LOGIN:    
Blog

How to save an image on the server

Posted by Rohatash Kumar Blogs | ASP.NET using VB.NET Jul 19, 2011
This blog defines how to save an image on the server.

This blog defines how to save an image on the server. In this blog we drag and drop a upload control on the form. upload an image to file from a local computer then uploded image will be save on the server with the saveAs method. PostedImages is folder within your application to save images.

Save Method - This method is used to save content of uploaded file.

ASPX code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

     <asp:FileUpload ID="fuOne" runat="server" />&nbsp;

      <asp:Button ID="cmdUpload" runat="server" Text="Upload" />

    <br />

     <br />

    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    </form>

</body>

</html>

.VB code

Imports System.IO

Partial Class _Default

    Inherits System.Web.UI.Page

    Protected Sub cmdUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdUpload.Click

        If Not fuOne.PostedFile Is Nothing Then

            fuOne.PostedFile.SaveAs(MapPath("PostedImages") & "\" & Path.GetFileName(fuOne.PostedFile.FileName))

            Label1.Text = "image has been saved."

        Else

            Label1.Text = "not saved "

        End If

    End Sub

End Class

share this blog :
post comment