源码如下:
private void btAddBook_Click(object sender, System.EventArgs e)
{
if(this.tbOherPublisher.Visible == true)
{
if(this.tbOherPublisher.Text == "")
{
this.lbInfo.Text = "出版社不能为空!";
return;
}
} ArrayList arr;
int ImageSize=0;
byte[] ImageBuffer;
string FileName;
FileInfo TpFile;
FileStream fs=null;
FileName=Server.MapPath("\\BookStore\\UpFile").ToString().Trim()+"\\"+ViewState["PostFileName"];
TpFile=new FileInfo(FileName);
ImageSize=(int)TpFile.Length;

int nIsSpecialPrice;
if(rbYes.Checked == true )
{
nIsSpecialPrice = 1;
}
else
{
nIsSpecialPrice = 0;
} try
{
fs=new FileStream(FileName,FileMode.OpenOrCreate);
BinaryReader r=new BinaryReader(fs);
r.BaseStream.Seek(0,SeekOrigin.Begin);
ImageBuffer=r.ReadBytes(ImageSize);
arr=new ArrayList();
// BookName, PublishingHouse, ClassInfo, Author, Translator, ISBN, Pages, PageLarge, SeriesName, 
// PublishDate, Price, Description, Abstract, BookCatalog, Cover, CommentNumber, HitNumber, SoldNumber,
// Status, SpecialPrice, Discount
arr.Add(this.tbBookName.Text.Trim());
arr.Add(this.ddPublisher.SelectedValue.Trim());
arr.Add(this.ddClassInfo.SelectedValue.Trim());
arr.Add(this.tbAuthor.Text.Trim());
arr.Add(this.tbTranslator.Text.Trim());
arr.Add(this.tbISBN.Text.Trim());
arr.Add(this.tbPage.Text.Trim());
arr.Add(this.ddPageLarge.SelectedValue.Trim());
arr.Add("");
arr.Add(this.tbPublishDate.Text.Trim());
arr.Add(this.tbPrice.Text.Trim());
arr.Add(this.tbDescription.Text.Trim());
arr.Add("");
arr.Add("");
arr.Add(ImageBuffer);
arr.Add("0");
arr.Add("0");
arr.Add("0");
arr.Add("1");
arr.Add(nIsSpecialPrice.ToString());
if(this.ddDiscount.Visible == true)
{
arr.Add(this.ddDiscount.SelectedValue.Trim());
}
else
{
arr.Add("90");
}
currentBook.AddBook(arr);
this.lbInfo.Text = "添加图书成功!";
this.tbAuthor.Text = "";
this.tbBookName.Text = "";
this.tbDescription.Text = "";
this.tbISBN.Text = "";
this.tbOherPublisher.Text = "";
this.tbPage.Text = "";
this.tbPrice.Text = "";
this.tbPublishDate.Text = "";
this.tbTranslator.Text = "";
this.imgBookCover.Visible = false;
}
catch(Exception er)
{
this.lbInfo.Text = "添加图书失败!";
throw new Exception(er.Message);
}
finally
{
fs.Close();
}
}出现以下错误:
“/BookStore”应用程序中的服务器错误。 
________________________________________
未能找到文件“C:\Inetpub\wwwroot\BookStore\UpFile\”。 行 182: FileName=Server.MapPath("\\BookStore\\UpFile")
.ToString().Trim()+"\\"+ViewState["PostFileName"];
行 183: TpFile=new FileInfo(FileName);
行 184: ImageSize=(int)TpFile.Length;
行 185:
行 186: int nIsSpecialPrice;
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.IO.FileNotFoundException: 未能找到文件“C:\Inetpub\wwwroot\BookStore\UpFile\”。源错误: 源文件: C:\Inetpub\wwwroot\BookStore\Admin\AdminDefault.aspx.cs    行: 184 堆栈跟踪: [FileNotFoundException: 未能找到文件“C:\Inetpub\wwwroot\BookStore\UpFile\”。]
   System.IO.__Error.WinIOError(Int32 errorCode, String str) +181
   System.IO.FileInfo.get_Length() +57
   BookStore.Admin.AdminDefault.btAddBook_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\BookStore\Admin\AdminDefault.aspx.cs:184
   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()________________________________________
版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573

解决方案 »

  1.   

    C:\Inetpub\wwwroot\BookStore\UpFile,没有找到文件啊,错误提示给的很清楚啊。
      

  2.   

    调试一下 看看 ViewState["PostFileName"] 里面有没有值,现象看来是空的
      

  3.   

    我用的是,电子工业出版社出版的《ASP.NET网络编程从基础到实践》这本书里的,实现一个完整的网络书店的代码,代码地址如下http://www.phei.com.cn/download/download.asp#d2 哪位大侠能帮小弟解决问题!小弟多谢了!!!