Hi,
How to save an image on the server ?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rohatash KumarPosted Jul 19, 2011, 8:26 AM
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 Pagetitle>
head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="fuOne" runat="server" />
<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
Rohatash KumarPosted Jul 20, 2011, 7:58 AM
Vijay YadavPosted Jul 19, 2011, 9:33 AM