62,046
社区成员
发帖
与我相关
我的任务
分享
行 45: string ty = File2.PostedFile.ContentType;
行 46:
行 47: File2.PostedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath(Pa) + ss);
行 48: s = ss;
行 49: return "3";
using System;
using System.IO;
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;
/// <summary>
/// upload 的摘要说明
/// </summary>
public class upload
{
public upload()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public string[] Resup ={ "上传失败或指定的文件不存在", "文件太大!", "格式不对,!", "上传成功!" };
public string s = string.Empty;
public string fname = string.Empty;
public string Up(System.Web.UI.HtmlControls.HtmlInputFile File2, string Pa)
{
//
// TODO: 在此处添加构造函数逻辑
//
if (File2.PostedFile.ContentLength.ToString() == "0")
{
return "0";
}
else
{
//获取文件名称
string ss;
fname = System.DateTime.Now.ToString().Replace("-", "").Replace(" ", "").Replace(":", "");
ss = System.DateTime.Now.ToString().Replace("-", "").Replace(" ", "").Replace(":", "") + Path.GetExtension(File2.PostedFile.FileName);
if (File2.PostedFile.ContentLength / 1024 > 10000000)
{ return "1"; }
else
{
string ty = File2.PostedFile.ContentType;
File2.PostedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath(Pa) + ss);
s = ss;
return "3";
//Up= ss;
}
}
}
}
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="AddHomework.aspx.cs" ValidateRequest="false" EnableEventValidation="false" Inherits="Admin_AddFile" Title="Untitled Page" %>
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
<asp:Content ID="Content1" runat="server" contentplaceholderid="ContentPlaceHolder1">
<table align="center" bgcolor="#e3ebfe" border="0" cellpadding="2" cellspacing="1"
style="margin-top: 8px" width="98%">
<tr>
<td style="WIDTH: 3%; HEIGHT: 21px" class="td2" align="center">
作业名称:</td>
<td style="HEIGHT: 21px" class="td2" colspan="3">
<asp:TextBox ID="TextBox1" runat="server" CssClass="label" Width="558px"></asp:TextBox></td>
</tr>
<tr>
<td align="center" class="td2" style="width: 3%; height: 21px">
上传作业:</td>
<td align="left" class="td2" colspan="3" style="height: 21px">
<asp:TextBox ID="pic" runat="server" CssClass="inputBox" ReadOnly="True" Width="72px"></asp:TextBox><input
id="file1" runat="server" class="inputBox" style="width: 141px" type="file" /><asp:Button
ID="Button2" runat="server" CausesValidation="False" CssClass="formbutton" Height="22px"
OnClick="Button1_Click" Text="上传" Width="58px" /><asp:Label ID="Label1" runat="server"
Visible="False" Width="60px"></asp:Label><input id="Hidden1" runat="server" type="hidden" /></td>
</tr>
<tr>
<td style="WIDTH: 3%; HEIGHT: 54px" class="td2" align="center">
内容说明:</td>
<td style="WIDTH: 23%; HEIGHT: 54px" class="td2" colspan="7">
<FCKeditorV2:FCKeditor ID="ArticleContent" runat="server" BasePath="~/FCKeditor/">
</FCKeditorV2:FCKeditor>
</td>
</tr>
<tr bgcolor="#e7e7e7">
<td align="center" colspan="10" height="24">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="添加" /></td>
</tr>
</table>
</asp:Content>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
public partial class Admin_AddFile : System.Web.UI.Page
{
SqlHelper data = new SqlHelper();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string res;
upload up = new upload();
res = up.Up(file1, "../files/");
this.Label1.Visible = true;
this.Label1.Text = up.Resup[Convert.ToInt32(res)];
this.pic.Text = up.s;
Hidden1.Value = up.fname;
}
protected void Button1_Click1(object sender, EventArgs e)
{
string filename = Hidden1.Value;
int i = this.pic.Text.LastIndexOf(".");
string newname = this.pic.Text.Substring(i);//获取文件的扩展名
string sql = "insert into Homework(TitleName,FileDs,FilePath,Ename,FileName)values('" + TextBox1.Text.Trim() + "','" + ArticleContent.Value + "','" + pic.Text + "','" + newname + "','" + filename + "')";
data.RunSql(sql);
Alert.AlertAndRedirect("添加成功继续添加", "Homework.aspx");
}
}