源码如下:
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
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
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货