<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 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 id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server"/>
<asp:Button ID="Button1" runat="server" Text="Upload!" /><br />
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:HyperLink ID="url1" runat="server" Text='<%# Eval("Name") %>' NavigateUrl='<%# "~/Uploads/" + Eval("Name") %>' />
</ItemTemplate>
<SeparatorTemplate>
<br />
</SeparatorTemplate>
</asp:Repeater>
</form>
</body>
</html>
Download_Upload ASP.NET
Есть код в aspx
Код:
Код:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
private readonly string uploads_dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Uploads");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void FileUpload1_Load(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
HttpPostedFile user_file = FileUpload1.PostedFile;
DirectoryInfo uploads = new DirectoryInfo(uploads_dir);
if (!uploads.Exists)
uploads.Create();
string user_file_server_name = Path.Combine(uploads.FullName, Path.GetFileName(user_file.FileName));
using (FileStream stream = new FileStream(user_file_server_name, FileMode.Create, FileAccess.Write, FileShare.None))
{
byte[] buffer = new byte[4096];
int bytes_read = 0;
do
{
stream.Write(buffer, 0, bytes_read);
bytes_read = user_file.InputStream.Read(buffer, 0, buffer.Length);
} while (bytes_read > 0);
}
}
}
protected void Page_PreRender(object sender, EventArgs e)
{
DirectoryInfo uploads = new DirectoryInfo(uploads_dir);
if (!uploads.Exists)
uploads.Create();
Repeater1.DataSource = uploads.GetFiles();
Repeater1.DataBind();
}
}
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
private readonly string uploads_dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Uploads");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void FileUpload1_Load(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
HttpPostedFile user_file = FileUpload1.PostedFile;
DirectoryInfo uploads = new DirectoryInfo(uploads_dir);
if (!uploads.Exists)
uploads.Create();
string user_file_server_name = Path.Combine(uploads.FullName, Path.GetFileName(user_file.FileName));
using (FileStream stream = new FileStream(user_file_server_name, FileMode.Create, FileAccess.Write, FileShare.None))
{
byte[] buffer = new byte[4096];
int bytes_read = 0;
do
{
stream.Write(buffer, 0, bytes_read);
bytes_read = user_file.InputStream.Read(buffer, 0, buffer.Length);
} while (bytes_read > 0);
}
}
}
protected void Page_PreRender(object sender, EventArgs e)
{
DirectoryInfo uploads = new DirectoryInfo(uploads_dir);
if (!uploads.Exists)
uploads.Create();
Repeater1.DataSource = uploads.GetFiles();
Repeater1.DataBind();
}
}
Error1The name 'FileUpload1' does not exist in the current context C:UsersleraDocumentsVisual Studio 2010ProjectsWebApplication1WebApplication1Default.aspx.cs
Error3The name 'Repeater1' does not exist in the current context C:UsersleraDocumentsVisual Studio 2010ProjectsWebApplication1WebApplication1Default.aspx.cs
Cуть ошибок понятна, но исправить не получается. Может кто подскажет как
Поэтому компилятор говорит , что в пространстве имен нет 'FileUpload1', 'Repeater1'
Так делать нельзя, точнее нужно делать привязку имен проекта.
Для этого начать новый проект например:
Код:
protected void FileUpload1_Load(object sender, EventArgs e)
// вместо FileUpload1 будет другое имя которое Вы задали or по умолчанию проекта
// Вот тогда можно вставить код
protected void Новое!!!_Load(object sender, EventArgs e)
// вместо FileUpload1 будет другое имя которое Вы задали or по умолчанию проекта
// Вот тогда можно вставить код
protected void Новое!!!_Load(object sender, EventArgs e)
Project - Add - Class