Description
This application is in ASP.NET which will allow you to upload images to an XML file which serves as the database for the uploaded files. You can retrieve these files along their properties from the xml file.
In this application I have made use of asp.net Web controls as well as Html controls. I have used a cascading stylesheet for formatting purpose. Xml file serves as a database for the uploaded files. The upload.aspx file is to upload the images to the database and show.aspx file is to retrieve the files from the database. Apart from this there is mystyle.css file which is a stylesheet and there is upload.xml file which stores all the uploaded files.
Code for upload.aspx:
<%@ Page Language="C#" EnableSessionState="False" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%-- These are the imported namespaces needed to run the guest book --%>
<html>
<head>
<title>Uploading Files.</title>
<script language="C#" runat="server">
//This method is called when the upload button is clicked
public void Submit_Click(Object sender, EventArgs e)
{
//the path to the Xml file which will contain all the data
string dataFile = "db/upload.xml";
try
{
//proceed only if the file is posted
if (file.PostedFile != null)
{
errmess.Text = "";
//Open a FileStream to the Database in read mode
FileStream fin;
fin = new FileStream(Server.MapPath(dataFile), FileMode.Open, FileAccess.Read,
FileShare.ReadWrite);
//Create a DataSet object
DataSet guestData = new DataSet();
//Read data from the Database
guestData.ReadXml(fin);
fin.Close();
//extract the filename from the full file path
string nam = file.PostedFile.FileName;
int i = nam.LastIndexOf("\\");
string newnm = nam.Substring(i);
//Create a new DataRow from the DataSet Schema
DataRow newRow = guestData.Tables[0].NewRow();
//Fill the DataRow with form values
newRow["title"] = title.Text;
newRow["file"] = file.PostedFile.FileName;
newRow["length"] = file.PostedFile.ContentLength.ToString();
newRow["contenttype"] = file.PostedFile.ContentType;
//Add the row to the DataSet
guestData.Tables[0].Rows.Add(newRow);
//Create another filestream to the DataBase file in write mode
FileStream fout;
fout = new FileStream(Server.MapPath(dataFile), FileMode.Open, FileAccess.Write,
FileShare.ReadWrite);
guestData.WriteXml(fout, XmlWriteMode.WriteSchema);
fout.Close();
//Hide the Form Panel
formPanel.Visible = false;
//Display the view Panel
thankPanel.Visible = true;
}
}
catch (Exception edd)
{
//catch any other exception that occur
errmess.Text = "Cannot write to XML file because " + edd.ToString();
}
}
</script>
</head>
<link href="mystyle.css" type="text/css" rel="stylesheet">
<body topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">
<%-- Include a header file 'header.inc' --%>
<!-- #Include File="header.inc" -->
<asp:Label ID="errmess" Text="" Style="color: #FF0000" runat="server" />
<asp:Panel ID="formPanel" runat="server">
<form id="Form1" runat="server" enctype="multipart/form-data" action="upload.aspx">
<table border="0" width="80%" align="Center">
<tr class="rowstyle">
<td>
Title :</td>
<td>
<asp:TextBox class="textstyle" Text="" ID="title" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="title"
Display="static" runat="server">*</asp:RequiredFieldValidator></td>
</tr>
<tr class="rowstyle">
<td>
File :</td>
<td>
<input type="file" class="textstyle" text="" id="file" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="file"
Display="static" runat="server">*</asp:RequiredFieldValidator></td>
</tr>
vatika manishPosted Jul 10, 2011, 10:01 PM
Can you tell me how to make this XML work for my website www.wtccars.com I was looking for a Xml file to Upload my stock to my website i dont know how to create Xml file and I dont know How to upload please can you help me
Kevin KnorrPosted Nov 17, 2008, 4:23 PM
Does not run, Errors out with a variety of errors.