使用FileUpload控件上传图片,上传不到文件夹,数据库也没有写入,图片无法显示。

walkscan 2009-01-08 07:52:48
使用FileUpload控件上传图片,图片上传不到文件夹,数据库也没有写入图片的表,图片无法显示。但其他都正常,都能显示
前台页面代码:


<body style="background-image: url(../images/right.png); background-repeat: no-repeat;">
<form id="form1" runat="server">
<div>
<br />
<br />
<br />
<br />
 
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="news_id"
DataSourceID="newsadd1" Height="352px" Width="700px">
<Fields>
<asp:BoundField DataField="news_id" HeaderText="新闻编号" InsertVisible="False" ReadOnly="True"
SortExpression="news_id">
<HeaderStyle Height="20px" Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="news_title" HeaderText="新闻标题" SortExpression="news_title">
<HeaderStyle Height="25px" />
</asp:BoundField>
<asp:TemplateField HeaderText="新闻内容" SortExpression="news_content">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("news_content") %>' Width="199px"></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<CE:Editor ID="Editor1" runat="server" AutoConfigure="Simple" AutoParseClasses="True"
BorderColor="#C0C0C0" CodeViewTemplateItemList="Save,Print,Cut,Copy,Paste,Find,ToFullPage,FromFullPage,SelectAll"
EditorOnPaste="ConfirmWord" MaxHTMLLength="0" MaxTextLength="0" Text='<%# Bind("news_content", "{0}") %>'
Width="550px">
<FrameStyle BackColor="White" BorderColor="#C0C0C0" BorderStyle="Solid" BorderWidth="1px"
CssClass="CuteEditorFrame" Height="100%" Width="550px" />
</CE:Editor>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("news_content") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="news_time" DataFormatString="{0:d}" HeaderText="发布时间"
HtmlEncode="False" SortExpression="news_time">
<HeaderStyle Height="20px" />
</asp:BoundField>
<asp:TemplateField HeaderText="新闻图片" SortExpression="news_photo">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("news_photo") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("news_photo") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Height="30px" />
</asp:TemplateField>
<asp:BoundField DataField="news_author" HeaderText="新闻作者" SortExpression="news_author">
<HeaderStyle Height="20px" />
</asp:BoundField>
<asp:CommandField ButtonType="Button" ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:AccessDataSource ID="newsadd1" runat="server" DataFile="~/App_Data/jinhai.mdb"
DeleteCommand="DELETE FROM [tb_news] WHERE [news_id] = ?" InsertCommand="INSERT INTO [tb_news] ([news_title], [news_content], [news_time], [news_author], [news_photo]) VALUES (?, ?, ?, ?, ?)"
SelectCommand="SELECT * FROM [tb_news]" UpdateCommand="UPDATE [tb_news] SET [news_title] = ?, [news_content] = ?, [news_time] = ?, [news_author] = ?, [news_photo] = ? WHERE [news_id] = ?">
<DeleteParameters>
<asp:Parameter Name="news_id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="news_title" Type="String" />
<asp:Parameter Name="news_content" Type="String" />
<asp:Parameter Name="news_time" Type="DateTime" />
<asp:Parameter Name="news_author" Type="String" />
<asp:Parameter Name="news_photo" Type="String" />
<asp:Parameter Name="news_id" Type="Int32" />
</UpdateParameters>
<InsertParameters>

<asp:Parameter Name="news_title" Type="String" />
<asp:Parameter Name="news_content" Type="String" />
<asp:Parameter Name="news_time" Type="DateTime" />
<asp:Parameter Name="news_author" Type="String" />
<asp:Parameter Name="news_photo" Type="String" />
</InsertParameters>
</asp:AccessDataSource>

</div>
</form>
</body>


后台页面代码:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class admin_newsadd : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DetailsView1.DefaultMode = DetailsViewMode.Insert;
}
protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
{


}
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
FileUpload filel;
filel = (FileUpload)DetailsView1.FindControl("fileupload1");
string filePath;
filePath = Server.MapPath("../newsimage/" + filel.FileName);
filel.SaveAs(filePath);
newsadd1.InsertParameters["news_photo"].DefaultValue = filel.FileName;
}
}
...全文
1000 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
shengyongwang 2009-01-08
  • 打赏
  • 举报
回复
看来只有调试了,光看代码也看不出个名堂来。
bdhwjs 2009-01-08
  • 打赏
  • 举报
回复
帮忙UP吧。。。

没有异常提示吗?权限开了吗???

断点看一下卡到哪里了,然后具体问题具体分析,这么COPY出来的代码很难帮您分析。。。
Part1第一部分: 相信大家找得到该书的源代码部分 也就是这部分内容 因此我便无偿奉送 让大家下载试试。 若感觉可以方可继续下载电子书部分。 1.本书1~21章所附代码的运行环境 操作系统:Windows Server 2003或Windows XP Professional 开发环境:Microsoft Visual Studio 2005 数据库:SQL Server 2005 Web服务器:IIS 5.1及以上版本 2.本书所附光盘范例 第1章(\Chapter 01) 示例描述:本章演示ASP.NET 2.0网站的预编译以及学习ASP.NET 2.0的前置知识。 WebSite文件夹 创建的ASP.NET 2.0 Web站点。 www文件夹 第一个用C#开发的Web应用程序。 bianyi.bat 编译网站的批处理文件。 form.html 表单范例。 css.html CSS范例。 第3章(\Chapter 03) 示例描述:本章介绍C# 2.0程序设计基础。 3-01.cs 第一个C#程序。 3-02.cs 不导入命名空间来改写程序3-01.cs。 3-03.cs ReadLine()方法读数据。 3-04.cs 常量的使用。 3-05.cs 整型类型的使用。 3-06.cs 结构类型的使用。 3-07.cs 枚举类型的使用。 3-08.cs 用一个输入参数通过值传递一个变量给一个方法。 3-09.cs 一维数组的使用。 3-10.cs 使用代理类型。 3-11.cs 使用接口。 3-12.cs 装箱操作。 3-13.cs 字符串操作。 3-14.cs if语句的使用。 3-15.cs switch语句的使用。 3-16.cs while语句的使用。 3-17.cs do-while语句的使用。 3-18.cs for语句的使用。 3-19.cs 异常捕获:try-catch语句的使用。 3-20.cs 异常捕获:try-finally语句的使用。 3-21.cs 异常捕获:try-catch-finally语句的使用。 3-22.cs get和set对属性的值进行读写操作。 3-23.cs 方法的使用。 3-24.cs 继承演示。 3-25.cs 多态性演示。 第4 章(\Chapter 04) 示例描述:本章学习ASP.NET 2.0页面基本对象。 4-01.aspx aspx页面中添加一个Lable标签。 4-02.aspx 读出Application的属性值。 4-03.aspx 读出SessionID的值。 4-04.aspx 创建Session对象。 4-05.aspx 读取传递的Session值并显示。 4-06.aspx 使用Response对象的Write()方法。 4-07.aspx 使用Response对象的End()方法。 4-08.html 以post方式提交数据到4-08.aspx的表单。 4-08.aspx 接收表单数据并进行处理。 4

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧