ASP.NET
示例
第一个示例演示如何创建 FileUpload 控件,该控件将文件保存到代码中指定的路径。
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void UploadButton_Click(object sender, EventArgs e)
{
// Specify the path on the server to
// save the uploaded file to.
String savePath = @"c:\temp\uploads\";
// Before attempting to perform operations
// on the file, verify that the FileUpload
// control contains a file.
if (FileUpload1.HasFile)
{
// Get the name of the file to upload.
String fileName = FileUpload1.FileName;
// Append the name of the file to upload to the path.
savePath += fileName;
// Call the SaveAs method to save the
// uploaded file to the specified path.
// This example does not perform all
// the necessary error checking.
// If a file with the same name
// already exists in the specified path,
// the uploaded file overwrites it.
FileUpload1.SaveAs(savePath);
// Notify the user of the name of the file
// was saved under.
UploadStatusLabel.Text = "Your file was saved as " + fileName;
}
相关文档:
数据绑定概述和语法
ASP.NET 引入了新的声明性数据绑定语法。这种非常灵活的语法允许开发人员不仅可以绑定到数据源,而且可以绑定到简单属性、集合、表达式甚至是从方法调用返回的结果。下表显示了新语法的一些示例。
简单属性 Customer: <%# custID %>
集合 Orders: <asp:ListBox id="List1" datasour ......
一、上传图片:
将图片存储在image文件夹中,然后把图片的路径存在数据库里,这样用的时候从数据库中搜索出路径然后绑定在前台页面的<image/>标签中,就能显示我们想要的图片。
前台代码:
商品图片:<asp:FileUpload ID="ImageUpload" runat="server" />
<asp:Label ID="TipF ......
using System;
using System.Collections.Generic;
using System.Text;
namespace PublicClass
{
public static class Log
{
public static void WriteLine(string line)
{
......
使用 FileUpload 控件,可以为用户提供一种将文件从其计算机发送到服务器的方法。
一、功能
可使用 FileUpload 控件执行下列操作:
·使用户能够上载存储在服务器上的特定位置的文件。
·限制可上载的文件的大小。
·在存储上载的文件之前检查其属性。
二 ......