日期:2014-05-17  浏览次数:21258 次

求助一下
本人以前没搞过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
  + "','"