vs 2005,一个上传页面,为什么上传不了?
vs 2005,一个上传页面,为什么上传不了?数据库中没有插入,本地服务器上也没有新上传的文件,也没有错误提示,源码:
using System;
using System.Collections;
using System.ComponentModel;
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 com.fengyin.project.fmrat.code;
using System.IO;
using System.Data.SqlClient;
using System.Configuration;
namespace com.fengyin.project.fmrat
{
/// <summary>
/// user_Upload_video 的摘要说明。
/// </summary>
public partial class user_Upload_video : System.Web.UI.Page
{
SqlConnection con = DBConn.createCon();
// private DBConn dbconn = new DBConn();
protected void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if((Page.Session["username"]==null))
{
Response.Write("<script>alert('请您先登录!');window.location.href='login.aspx?comefrom=user_Upload_video.aspx';</script>");
}
if(!Page.IsPostBack)
{
this.init();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
#endregion
#region 初始化各个控件
private void init()
{
string txtChannel = "select * from mm_labels";
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand(txtChannel, con);
DataSet dsChannel = new DataSet();
sda.Fill(dsChannel, "labels");
//DataSet dsChannel = new DataSet();
this.rbl_channel.DataSource = dsChannel.Tables[0];
//从数据库绑定单行按钮组中的标签
//this.rbl_channel.DataSource = dsChannel;
this.rbl_channel.DataTextField = dsChannel.Tables[0].Columns[1].ToString();
this.rbl_channel.DataValueField = dsChannel.Tables[0].Columns[0].ToString();
this.rbl_channel.DataBind();
if(this.rbl_channel.Items.Count>0)
{
this.rbl_channel.Items[0].Selected = true;
}
}
#endregion
private string strPicPath
{
get
{
return System.Configuration.ConfigurationSettings.AppSettings["picPath"];
}
set
{
this.strPicPath = value;
}
}
private string strVideoPath
{
get
{
return System.Configuration.ConfigurationSettings.AppSettings["videoPath"];
}
set
{
this.strVideoPath = value;
}
}
protected void Submit_Click(object sender, System.EventArgs e)
{
//获取各个控件的值
if(Page.IsValid)
{
int lib = Convert.ToInt32(this.rbl_channel.SelectedValue);
string txtTitle = this.txt_title.Value;
string txtResume = this.txt_resume.Value;
string txtPostPicExt = Path.GetExtension(this.file_pic.PostedFile.FileName);
string txtPostVideoExt = Path.GetExtension(this.file_video.PostedFile.FileName);
//设置图片路径
string picPath = Server.MapPath(this.strPicPath);
//设置视频路径
string videoPath = Server.MapPath(this.strVideoPath);
string picSaveFile = "";
string videoSaveFile = "";
if(!(txtPostPicExt.Equals(".bmp") || txtPostPicExt.Equals(".jpg") || txtPostPicExt.Equals(".gif")))
{
Response.Write("<script>alert('您只能选择bmp||gif||jpg格式的图片!');</script>");
return;
}
if(!(txtPostVideoExt.Equals(".rm") || txtPostVideoExt.Equals(".wmv") || txtPostVideoExt.Equals(".mp3")))
{
Response.Write("<script>alert('您只能选择rm||wmv||mp3格式的媒体文件!');</script>");
return;
}
//确定播放器的类型
string strPlayerType = "wm";
if(txtPostVideoExt.Equals(".rm"))
{
strPlayerType = "rm";
}
//开始向上传
string txtRndString = this.rndString();
picSaveFile += Session["username"].ToString();
picSaveFile += Path.GetFileNameWithoutExtension(this.file_pic.PostedFile.FileName);
picSaveFile += txtRndString;
picSaveFile += Path.GetExtension(this.file_pic.PostedFile.FileName);
picPath += picSaveFile;
this.file_pic.PostedFile.SaveAs(picPath);
videoSaveFile += Session["username"].ToString();
videoSaveFile += Path.GetFileNameWithoutExtension(this.file_video.PostedFile.FileName);
videoSaveFile += txtRndString;
videoSaveFile += Path.GetExtension(this.file_video.PostedFile.FileName);
videoPath += videoSaveFile;
this.file_video.PostedFile.SaveAs(videoPath);
string mysql = "insert into mm_mediaFile(lid,vodname,vodAuthor,vodResume,vodFileName,vodPicName,playerType) values(";
mysql += lib;
mysql += ",'" + txtTitle + "'";
mysql += ",'" + Session["username"].ToString() + "'";
mysql += ",'" + txtResume + "'";
mysql += ",'" + @videoSaveFile + "'";
mysql += ",'" + @picSaveFile + "'";
mysql += ",'" + strPlayerType + "'";
mysql += ")";
//int intResult = dbconn.ExeSQL(mysql);
con.Open();
SqlCommand cmd = new SqlCommand(mysql, con);
int intResult = cmd.ExecuteNonQuery();
if (intResult > 0)
{
Response.Write("<script>alert('已经发布成功!');</script>");
}
}
}
private string rndString()
{
DateTime date = DateTime.Now;
int year = date.Year;
int month = date.Month;
int day = date.Day;
int hour = date.Hour;
int minute = date.Minute;
int second = date.Second;
return "" + year + "" + month + "" + day + "" + hour + "" + minute + "" + second;
}
}
} --------------------编程问答-------------------- 把页面代码也发上来可以调试看看 --------------------编程问答-------------------- 跟一下 --------------------编程问答-------------------- <%@ Page language="c#" CodeFile="user_Upload_video.aspx.cs" AutoEventWireup="true" Inherits="com.fengyin.project.fmrat.user_Upload_video" %>
<%@ Register TagPrefix="uc1" TagName="common_topic" Src="controls/common_topic.ascx" %>
<%@ Register TagPrefix="uc1" TagName="common_bottom" Src="controls/common_bottom.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>用户视频上传</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1"/>
<meta name="CODE_LANGUAGE" content="C#"/>
<meta name="vs_defaultClientScript" content="JavaScript"/>
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"/>
<link href="inc/style.css" rel="stylesheet" type="text/css"/>
</head>
<body MS_POSITIONING="GridLayout">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"><uc1:common_topic id="Common_topic1" runat="server"></uc1:common_topic></td>
</tr>
</table>
<table width="970" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
<tr>
<td width="21%" height="268" valign="top">
<table height="297" cellspacing="0" cellPadding="0" width="200" align="center" border="0">
<tr>
<td><img height="40" src="images/zhuche.gif" width="200"></td>
</tr>
<tr>
<td><img height="12" src="images/affiche_r2_c1.gif" width="200"></td>
</tr>
<tr>
<td height="229" valign="top" background="images/affiche_r3_c1.gif">
<table cellSpacing="0" cellPadding="2" width="179" align="center" border="0">
<tr>
<td height="217" valign="top">
<table width="128" height="147" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td> </td>
</tr>
<tr>
<td height="19">一、阅读并同意协议 <span class="STYLE15">√</span>
</td>
</tr>
<tr>
<td height="19">二、填写注册资料<span class="STYLE15">√</span></td>
</tr>
<tr>
<td height="22">三、完成注册<span class="STYLE15">√</span></td>
</tr>
<tr>
<td height="19">四、上传资料填写 <span class="STYLE15">→</span></td>
</tr>
<tr>
<td height="20">五、上传媒体文件</td>
</tr>
<tr>
<td>
六、完成上传</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td><img height="16" src="images/affiche_r5_c1.gif" width="200"></td>
</tr>
</table>
</td>
<td rowspan="4" valign="top" style="width: 76%">
<form id="Form1" method="post" runat="server">
<table width="744" height="555" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="744" height="555" valign="top">
<table width="622" height="52" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="622" height="52"><img src="images/zhuc1.gif" width="617" height="40"></td>
</tr>
</table>
<table width="750" height="503" border="0" cellpadding="6" cellspacing="1" id="zhuce" style="BORDER-COLLAPSE: collapse">
<tbody>
<tr>
<td class="td3" colspan="3" style="height: 44px"><div align="left"><font color="red">以下表单带 * 号的为必填项,请仔细按照要求填写</font></div>
</td>
</tr>
<tr>
<td align="right" width="11%"><strong>标题:</strong></td>
<td colspan="2"><div align="left">
<input class="inpbox" maxlength="20" size="18" name="title" id="txt_title" runat="server">
<asp:RequiredFieldValidator ControlToValidate="txt_title" Display="Dynamic" runat="server" id="RequiredFieldValidator1">填写有意义的标题</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ControlToValidate="txt_title" ValidationExpression=".{1,}" Display="Dynamic" runat="server"
id="RegularExpressionValidator1">填写有意义的标题</asp:RegularExpressionValidator>
<font color="red">*</font></div>
</td>
</tr>
<tr>
<td width="11%" height="73" align="right"><strong>简介:</strong></td>
<td colspan="2"><div align="left">
<textarea name="brief" cols="40" rows="4" class="inpbox" id="txt_resume" runat="server"></textarea>
<font color="red">*</font></div>
</td>
</tr>
<tr>
<td width="11%" height="33" align="right"><strong>频道:</strong></td>
<td colspan="2"><div align="left">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="2%" align="center" style="height: 38px"><font color="red">*</font></td>
<td width="98%" style="height: 38px"><font color="red">
<asp:RadioButtonList ID="rbl_channel" runat="server" RepeatDirection="Horizontal"></asp:RadioButtonList>
</font>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td width="11%" height="37" align="right"><strong>图片:</strong></td>
<td colspan="2"><INPUT id="file_pic" style="WIDTH: 472px; HEIGHT: 22px" type="file" size="59" name="File1"
runat="server"><font color="red">*</font>
</td>
</tr>
<tr>
<td width="11%" rowspan="3" align="right"><strong>上传媒体:</strong></td>
<td width="37%" height="98"><p align="left" class="upload_notice">
支持的文件格式<br/>
微软视频 :.wmv<br/>
Real Player :.rm<br/>
音频格式 :.mp3</p>
</td>
<td width="52%"><p align="left" class="upload_notice">媒体文件最大不能超过100M,并且要至少大于50KB</p>
<p align="left">请不要上传有版权和违法的内容的文件,所有因内容违法(暴力、反动等)、版权引起问题,其责任由发布者承担。</p>
</td>
</tr>
<tr>
<td height="52" colspan="2"><INPUT id="file_video" style="WIDTH: 472px; HEIGHT: 22px" type="file" size="59" name="File2"
runat="server"></td>
</tr>
<tr>
<td class="td2" align="center" colspan="3" style="height: 61px"><input id="IacceptCheck2" disabled type="checkbox" checked value="1" name="IacceptCheck">
我接受 <a onClick="window.open('reg2.htm','chengs','scrollbars=yes,resizable=no,width=595,height=500,menubar=no,top=168,left=168')"
href="javascript:;">[用户协议]</a><asp:Button Text="同意服务条款,确认上传" runat="server" ID="Submit"></asp:Button></td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</form>
<table width="100%" height="37" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="25" background="images/bgh.gif"> </td>
</tr>
<tr>
<td height="11" bgcolor="#00ccff"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="313" valign="top"><FONT face="宋体"></FONT></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"><uc1:common_bottom id="Common_bottom1" runat="server"></uc1:common_bottom></td>
</tr>
</table>
</body>
</html> --------------------编程问答-------------------- 楼主先打断点跟一下,看看上传文件到服务器的代码有没有被执行,另外上传的目录有没有权限。 --------------------编程问答-------------------- 我电脑系统是2003,上传的两个文件夹都设为web共享了,并且everyone具有写入权限,我设置断点跟过,上传文件到服务器没有执行,不知为什么不执行,没找出错误 --------------------编程问答-------------------- 怎么没人了呢?关注下啊,还是解决不了,急~~~~~~~ --------------------编程问答-------------------- private string strPicPath
{
get
{
return System.Configuration.ConfigurationSettings.AppSettings["picPath"];
}
set
{
this.strPicPath = value;
}
}
private string strVideoPath
{
get
{
return System.Configuration.ConfigurationSettings.AppSettings["videoPath"];
}
set
{
this.strVideoPath = value;
}
}
还有谁能帮我解释下这段代码的用法和作用,不太明白,稀里糊涂 --------------------编程问答-------------------- 上传文件到服务器的代码前有没有 IF 之类的条件判断,如果条件没有满足,就可能跳过。
另外楼主的这段代码是从VS2003 上改到 VS2005上的吧?上传控件直接用ASP.NET 2.0自带就好了,不要再用 HTTP的了。 --------------------编程问答-------------------- 首先谢过各位,我再重新做个页面,直接用vs 2005里面的控件,再试试,谢了 --------------------编程问答-------------------- 我也有这个问题,我在本地调试就上传不了,能传到文件夹插入不到数据库,也不报错,不明白哪里写错了 --------------------编程问答-------------------- 打下断点一步步跟踪进去看哪一部没值了~ --------------------编程问答-------------------- 分真多。。。。。。
补充:.NET技术 , ASP.NET