using System;                       using System.Collections;
using System.Data;                  using System.Drawing;
using System.Web;                   using System.Web.SessionState;
using System.Web.UI;                using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;   using System.Data.SqlClient;
using System.ComponentModel;        using System.IO;
namespace mp3Publish
{   public class publish : System.Web.UI.Page
        {
 protected System.Web.UI.WebControls.TextBox txtmName;
//一些文本框的定义...
 protected System.Web.UI.WebControls.DropDownList ddlmPath;
 protected System.Web.UI.WebControls.Button btnSubmit;
 protected System.Web.UI.WebControls.DataGrid DataGrid1;
          public string sqlStr;
 protected System.Web.UI.WebControls.Button btnbrowse;
 protected System.Web.UI.HtmlControls.HtmlInputFile filMyFile;
 if(!this.IsPostBack)  {   this.BindDdl();  }
 private void BindDdl() {绑定的代码...}
 private void btnSubmit_Click(object sender, System.EventArgs e)
    {
     string filename,fname,path;
 filename=filMyFile.Value; //上传文件的路径
 fname=System.IO.Path.GetFileName(filename);  //获得要上传的文件的文件名带扩展名
          SqlConnection con = DBCon.con();
  con.Open();
 string cmdStr = "insert into mp3List values( 文本框里的值)"
 SqlCommand cmd = new SqlCommand(cmdStr,con);
 cmd.ExecuteNonQuery();
 this.BindDataGrid();
 cmd.Dispose();        con.Close();
 path=ddlmPath.SelectedItem.Text;
HttpPostedFile myFile = filMyFile.PostedFile;
         int nFileLen = myFile.ContentLength;
   Allocate a buffer for reading of the file
 byte[] myData = new byte[nFileLen];
 myFile.InputStream.Read(myData, 0, nFileLen);
    WriteToFile(path,ref myData);  //保存文件   }
      private void WriteToFile(string strPath, ref byte[] Buffer){
         FileStream newFile = new FileStream(strPath, FileMode.Create);
         newFile.Write(Buffer,0,Buffer.Length);  //???????
newFile.Close();  }
 private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
 {string delpath=e.Item.Cells[7].FindControl("mpath").ToString();
File.Delete(delpath);        }
运行后上传时 说“不支持 URI 格式。”

解决方案 »

  1.   

    “/www/mp3Publish”应用程序中的服务器错误。
    --------------------------------------------------------------------------------不支持 URI 格式。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ArgumentException: 不支持 URI 格式。源错误: 
    行 301: {
    行 302: // Create a file
    行 303: FileStream newFile = new FileStream(strPath, FileMode.Create);
    行 304:
    行 305: // Write data to the file
     源文件: d:\www\mp3publish\publish.aspx.cs    行: 303 堆栈跟踪: 
    [ArgumentException: 不支持 URI 格式。]
       System.IO.Path.GetFullPathInternal(String path) +270
       System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) +233
       System.IO.FileStream..ctor(String path, FileMode mode) +52
       mp3Publish.publish.WriteToFile(String strPath, Byte[]& Buffer) in d:\www\mp3publish\publish.aspx.cs:303
       mp3Publish.publish.btnSubmit_Click(Object sender, EventArgs e) in d:\www\mp3publish\publish.aspx.cs:206
       System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       System.Web.UI.Page.ProcessRequestMain() 这是点上传后出现的错误页面,请帮我看一看应怎么改,还有删除时删不掉文件。
      

  2.   

    strPath => Server.mappath(strPath);  ????
      

  3.   

    说具体点。没明白什么意思。
    还有个DB类
    public class DBCon
    {
    public DBCon()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    }
    public static SqlConnection con()
    {
    return new SqlConnection("datasource=192.168.0.111;database=db;");
    }
    public static string mp3UploadString()
    {
    return "http://211.93.94.155/Content/";
    }
    }
      

  4.   

    FileStream newFile = new FileStream(strPath, FileMode.Create);
    什么也没干啊,只创建了一个文件啊.