Subject: How Load An Image
Posted By: ctranjith Post Date: 11/17/2004 9:07:21 AM
Sir
   I am in great problem that I need to load an image from Client and save it in Server (jpeg ) file , Sir can you help me to do that and tell me what are controls that i need to do it and the code also for it in asp.net (using Vb).

Expecting reply


Reply By: bekim Reply Date: 11/20/2004 2:33:30 AM
You can look at: http://support.microsoft.com/default.aspx?scid=kb;en-us;315832
or here it the summary of that:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="WebApplication3.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
    <HEAD>
        <title>WebForm1</title>
        <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
        <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server" EncType="multipart/form-data" action="/?scid=WebForm1.aspx&fp=1">
            Image file to upload to the server: <INPUT id="oFile" type="file" runat="server" NAME="oFile">
            <asp:button id="btnUpload" type="submit" text="Upload" runat="server"></asp:button>
            <asp:Panel ID="frmConfirmation" Visible="False" Runat="server">
                <asp:Label id="lblUploadResult" Runat="server"></asp:Label>
            </asp:Panel>
        </form>
    </body>
</HTML>

Imports System.IO
Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected WithEvents btnUpload As System.Web.UI.WebControls.Button
    Protected WithEvents lblUploadResult As System.Web.UI.WebControls.Label
    Protected WithEvents frmConfirmation As System.Web.UI.WebControls.Panel
    Protected WithEvents oFile As System.Web.UI.HtmlControls.HtmlInputFile

#Region " Web Form Designer Generated Code "

    'The Web Form Designer requires this call.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

Private Sub Page_Init(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: The Web Form Designer requires this method call.
        'Do not use the code editor to modify it.
        InitializeComponent()
    End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
        'Insert user code to initialize the page here.
    End Sub

Private Sub btnUpload_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnUpload.Click
        Dim strFileName As String
        Dim strFilePath As String
        Dim strFolder As String

        strFolder = "C:\Temp\"

        'Get the name of the file that is posted.
        strFileName = oFile.PostedFile.FileName
        strFileName = Path.GetFileName(strFileName)

        'Create the directory if it does not exist.
        If (Not Directory.Exists(strFolder)) Then
            Directory.CreateDirectory(strFolder)
        End If

        'Save the uploaded file to the server.
        strFilePath = strFolder & strFileName
        If File.Exists(strFilePath) Then
lblUploadResult.Text = strFileName & " already exists on the server!"
        Else
            oFile.PostedFile.SaveAs(strFilePath)
lblUploadResult.Text = strFileName & " has been successfully uploaded."
        End If

        'Display the result of the upload.
        frmConfirmation.Visible = True

    End Sub
End Class



Go to topic 22252

Return to index page 711
Return to index page 710
Return to index page 709
Return to index page 708
Return to index page 707
Return to index page 706
Return to index page 705
Return to index page 704
Return to index page 703
Return to index page 702