首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

一下

2012-05-03 
求助一下本人以前没搞过asp,asp.net什么的东东,对这块不怎么了解,因工作需要写了个小小的程序,就是上传的,

求助一下
本人以前没搞过asp,asp.net什么的东东,对这块不怎么了解,因工作需要写了个小小的程序,就是上传的,在网页上功能可以实现,也可以写数据库,但是这个上传不是通过浏览器上传,是手机发送http请求上传文件,用手机发送请求就不行了,代码如下
Upload.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Upload.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 runat="server">
  <title></title>
</head>
<body>
  <form id="form1" runat="server" enctype="multipart/form-data">
  <div>
  <asp:FileUpload ID="FileUpload1" runat="server" />
  <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="上传" />
  </div>
  </form>
</body>
</html>


Upload.aspx.cs:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using System.Collections;
using System.Configuration;

public partial class _Default : System.Web.UI.Page
{
  string id="";
  string userName="";
  string type = "";
  protected void Page_Load(object sender, EventArgs e)
  {
   
  }

  private bool checkParams()
  {
  if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(type))
  {
  ClientScript.RegisterStartupScript(this.GetType(), "PopuScript", getScript("error."));
  return false;
  }
  return true;
  }
  protected void Button1_Click(object sender, EventArgs e)
  {
  id = Request["id"];
  userName = Request["user"];
  type = Request["type"];
  string path = AppDomain.CurrentDomain.BaseDirectory;
  string fileName = FileUpload1.FileName;
  long fileLength = FileUpload1.FileContent.Length;
  if (string.IsNullOrEmpty(fileName))
  {
  ClientScript.RegisterStartupScript(this.GetType(), "PopuScript", getScript("null"));
  return;
  }
  if (fileLength > 8 * 1024*1024)
  {
  ClientScript.RegisterStartupScript(this.GetType(), "PopuScript", getScript("file is to big"));
  return;
  }

  if (!checkParams())
  {
  return;
  }

  string filePath = ConfigurationManager.AppSettings["FilePath"].ToString();

  FileUpload1.SaveAs(filePath + userName + "/" + fileName);
  String sql = "insert into UserFile(uf_name, uf_filesize, uf_folder, uf_belongid,uf_filetype,"
  + "uf_belongname,uf_location,uf_detail,uf_title) values('"
  + fileName
  + "','"
  + FileUpload1.FileContent.Length
  + "','','"
  + id
  + "','"
  + type + "','" + userName + "','','','' )";
  if (SqlHelper.ExecuteNonQuery(SqlHelper.CONNSTR, CommandType.Text, sql) > 0)


  {
  ClientScript.RegisterStartupScript(this.GetType(), "PopuScript", getScript("success"));
  }
  else
  ClientScript.RegisterStartupScript(this.GetType(), "PopuScript", getScript("false"));
   
  }
  private string getScript(string message)
  {
  StringBuilder strScript = new StringBuilder();
  strScript.Append("<script type='text/javascript'>");
  strScript.Append("alert('"+message+"')");
  strScript.Append("</script>");
  return strScript.ToString();
  }
}


web.config代码


<?xml version="1.0"?>
<!--
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
<connectionStrings>
<add name="sqlconnection" providerName="System.Data.SqlClient" connectionString="server=localhost;database=SPE;uid=sopydb;pwd=sopydb"/>
</connectionStrings>
<appSettings>
<add key="FilePath" value="D:/Web/Capture/"/>
</appSettings>
<system.web>
<httpRuntime executionTimeout="240" maxRequestLength="81920"/>
<compilation debug="true"/>
<customErrors mode="Off"/>
</system.web>
</configuration>

各位大哥美女帮帮忙吧,在线等

[解决办法]
这段代码有什么问题?
[解决办法]
C#的语言不是这么写的。

热点排行