|
|
|
จะทำเว็บอัพโหลดVDO โดยอัพไปใส่ไว้ในfloder จากนั้นจะมีชื่อไฟล์ที่อยู่ในfloder ขึ้นมาแสดงเป็นรายการอ่ะคะ |
|
|
|
|
|
|
|
Code (C#)
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;
using System.IO;
using System.Text;
public partial class Main : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DirectoryInfo myDirInfo;
myDirInfo = new DirectoryInfo(Server.MapPath("upload/"));
FileInfo[] arrFileInfo = myDirInfo.GetFiles("*.*");
foreach (FileInfo myFileInfo in arrFileInfo)
{
HyperLink hyp = new HyperLink();
hyp.NavigateUrl = "Main.aspx?mov=" + myFileInfo.Name;
hyp.Text = myFileInfo.Name;
Literal lit = new Literal();
lit.Text = "<br />";
Panel1.Controls.Add(hyp);
Panel1.Controls.Add(lit);
}
if (Request.QueryString["mov"] != null)
{
String src = "upload/" + Request.QueryString["mov"];
Literal1.
Text = "<object classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6' id='Player1' style='width: 600px; height: 400px'><param name='URL' value='" + src + "'><param name='AutoStart' value='True'><param name='ShowControls' value='True'><param name='ShowStatusBar' value='True'><param name='ShowDisplay' value='True'><param name='AutoRewind' value='True'>" +
"<embed type='application/x-mplayer2'" +
"pluginspage='http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/'" + " width='352' height='352'" + " src='" + src + "'" + " autostart='False' showcontrols='True' showstatusbar='True' showdisplay='True' autorewind='True'></embed>" +
"</object>";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
โค้ดที่เขียนไว้อ่ะคะ Dropdownในรูปไม่เกี่ยวนะคะ สร้างแร้วทำต่อไม่ได้อ่ะค่ะ
|
|
|
|
|
Date :
2011-05-26 10:42:58 |
By :
mooae |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เก็บลง Database ซิครับ ง่ายดีครับ อ้างอิงได้ง่ายด้วย
Code (C#)
<%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<script runat="server">
void btnUpload_OnClick(Object sender, EventArgs e)
{
this.pnlUpload.Visible = false;
this.pnlSave.Visible = true;
if(!this.fiUpload.HasFile)
{
this.lblText.Text = "Please select upload file!";
}
else
{
this.fiUpload.SaveAs(Server.MapPath("Myfiles/"+fiUpload.FileName));
this.lblText.Text = "<b>" + fiUpload.FileName + "</b> Uploaded.<br>";
//*** Save to Database ***//
OleDbConnection objConn;
OleDbCommand objCmd;
String strConnString,strSQL;
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
Server.MapPath("database/mydatabase.mdb") + ";";
objConn = new OleDbConnection(strConnString);
objConn.Open();
strSQL = "INSERT INTO picture (PictureName) " +
"VALUES ('" + fiUpload.FileName + "')";
objCmd = new OleDbCommand();
objCmd.Connection = objConn;
objCmd.CommandType = CommandType.Text;
objCmd.CommandText = strSQL;
objCmd.ExecuteNonQuery();
objCmd = null;
objConn.Close();
objConn = null;
this.hplLink1.NavigateUrl = "AspNetFileUploadToDatabase1.aspx";
this.hplLink2.NavigateUrl = "AspNetFileUploadToDatabase2.aspx";
}
}
</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - Upload files</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Panel id="pnlUpload" runat="server">
<asp:FileUpload id="fiUpload" runat="server"></asp:FileUpload>
<input id="btnUpload" type="button" OnServerClick="btnUpload_OnClick" value="Upload" runat="server" />
</asp:Panel>
<asp:Panel id="pnlSave" Visible="false" runat="server">
<asp:Label id="lblText" runat="server"></asp:Label><br />
<asp:HyperLink id="hplLink1" runat="server">Upload again</asp:HyperLink>
,
<asp:HyperLink id="hplLink2" runat="server">View files</asp:HyperLink>
</asp:Panel>
</form>
</body>
</html>
Go to : (C#) ASP.NET Upload file to Database
|
|
|
|
|
Date :
2011-05-26 12:01:22 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อ่อค่ะ ขอบคุณค่ะ
|
|
|
|
|
Date :
2011-05-26 12:51:36 |
By :
mooae |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มีวิธีอื่นอีกมั้ยอ่ะคะ คือที่นี่เขาไม่อยากให้ใช้ฐานข้อมูลอ่ะ
|
|
|
|
|
Date :
2011-05-30 08:45:49 |
By :
mooae |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|