asp.net C#
.aspx主要代码
<TR>
<Th><%=reqTitle %> No.:</th>
<td> <asp:TextBox runat="server" Css />
(*)</TD>
</TR>
<TR>
<Th>File:</th>
<td> <input runat="server" type="file" >(*)</TD>
</TR>
<TR>
<TD colspan=2 align=middle><asp:Button runat="server" Text="" OnClick="btnUpload_Click" Css onMouseDown="this.style.backgroundImage='url(../Sales/images/Uploada3.gif)'"
onMouseOver="this.style.backgroundImage='url(../Sales/images/Uploada2.gif)'"
onMouseOut="this.style.backgroundImage='url(../Sales/images/Uploada1.gif)'"/>
<input type="button" name="close" value="" onMouseDown="this.style.backgroundImage='url(../Sales/images/close3.gif)'"
onMouseOver="this.style.backgroundImage='url(../Sales/images/close2.gif)'"
onMouseOut="this.style.backgroundImage='url(../Sales/images/close1.gif)'" onclick="javascript:self.close();"/></TD>
</TR>
.cs主要代码
if (File1.PostedFile.ContentLength != 0)
{
fileName = FileUtility.UploadFile(File1, Server.MapPath("~/PFImage/"),DateTime.Now.ToString("yyyyMMddHHmmddfff")+
System.IO.Path.GetFileName(File1.PostedFile.FileName));
if (fileName == "")
{
//上传失败
return;
}
else
{
//上传成功
}
}
文件上传类主要代码
命名空间
using System.IO;
using System.Net;
#region 上传文件
/// <summary>
/// 上传文件
/// </summary>
/// <param name="inputFile">System.Web.UI.HtmlControls.HtmlInputFile</param>
/// <param name="path">文件存储目录,物理文件路径</param>
/// <returns></returns>
public static string UploadFile(System.Web.UI.HtmlControls.HtmlInputFile inputFile, string path,string namedFileName)
{
try
{
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
inputFile.PostedFile.SaveAs(path + namedFileName);
}
catch (Exception)
{
namedFileName = "";
}
return namedFileName;
}
#endregion
用SaveFileDialog对象。
private void SaveButton_Click(object sender, EventArgs e) {
SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.InitialDirectory = @"C:\"; saveFileDialog1.Title = "Save text Files";
saveFileDialog1.CheckFileExists = true;
saveFileDialog1.CheckPathExists = true;
saveFileDialog1.DefaultExt = "txt";
saveFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
saveFileDialog1.FilterIndex = 2; saveFileDialog1.RestoreDirectory = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{ textBox1.Text = saveFileDialog1.FileName; }
}
他说的是 网页版的