how to create event management system website /Web applications / database management
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
protected void btnAdd_Click(object
sender, EventArgs e)
{
if
(upImage.HasFile)
{
if
(CheckFileType(upImage.FileName))
{
upImage.SaveAs(MapPath(upImage.FileName));
}
}
}
bool
CheckFileType(string fileName)
{
string
ext = Path.GetExtension(fileName);
switch
(ext.ToLower())
{
case
".gif":
return
true;
case
".png":
return
true;
case
".jpg":
return
true;
case
".jpeg":
return
true;
default:
return
false;
}
}
void
Page_PreRender()
{
string
upFolder = MapPath(".");
DirectoryInfo
dir = new DirectoryInfo(upFolder);
dlstImages.DataSource = dir.GetFiles();
dlstImages.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>FileUpload
File</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label
id="lblImageFile"
Text="Image File:"
AssociatedControlID="upImage"
Runat="server" />
<asp:FileUpload
id="upImage"
Runat="server" />
<br /><br />
<asp:Button
id="btnAdd"
Text="Add Image"
OnClick="btnAdd_Click"
Runat="server" />
<hr />
<asp:DataList
id="dlstImages"
RepeatColumns="4"
runat="server" Width="764px">
<ItemTemplate>
<asp:Image ID="Image1"
ImageUrl='<%# Eval("Name", "./{0}") %>'
style="width:200px"
Runat="server" />
<br />
<%# Eval("Name") %>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
fileUpload.aspx
<%@ Page Language="C#"
AutoEventWireup="true"
CodeFile="FileUpload.aspx.cs"
Inherits="FileUpload"
%>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />
<asp:Button ID="UPloadButton" runat="server" onclick="UPloadButton_Click"
Text="Upload" />
<br />
<asp:Label ID="Status_Label" runat="server" Text="Up Load Status"></asp:Label>
</div>
</form>
</body>
</html>
fileUpload.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web.Security;
using System.IO;
public partial
class FileUpload
: System.Web.UI.Page
{
protected void UPloadButton_Click(object
sender, EventArgs e)
{
if
(FileUpload1.HasFile)
{
try
{
string
filename =Path.GetFileName(FileUpload1.FileName);
FileUpload1.SaveAs(Server.MapPath("~/") + filename);
Status_Label.Text = "Upload status: File uploaded!";
}
catch(Exception ex)
{
Status_Label.Text = "Upload status: The file could not be uploaded. The
following error occured: " + ex.Message;
}
}
if(FileUpload1.HasFile)
{
try
{
if(FileUpload1.PostedFile.ContentType=="image/jpeg")
{
if(FileUpload1.PostedFile.ContentLength<200)
{
string
filename = Path.GetFileName(FileUpload1.FileName);
FileUpload1.
SaveAs(Server.MapPath("~/") +
filename);
Status_Label.Text = "Upload status: File uploaded!";
}
Else
Status_Label.Text
= "Upload status: The file has to be less than
100 kb!";
}
else
Status_Label.Text = "Upload
status: Only JPEG files are accepted!";
}
catch
(Exception ex)
{
Status_Label.Text
= "Upload status: The file could not be
uploaded. The following error occured: " + ex.Message;
}
}
}
}
Contact : +91-9040573923, +91-7008182025
http://sradhawebcreations.com/
http://sradhawebcreations.blogspot.in/
https://facebook.com/sradhawebcreations
http://sradhawebcreations.com/
http://sradhawebcreations.blogspot.in/
https://facebook.com/sradhawebcreations