日期:2014-05-19  浏览次数:20776 次

新手请教,用c#如何读取别人机子上的视频文件并保存
用c#如何读取别人机子上的视频文件并保存?

------解决方案--------------------
我现在也正在做一个同学录.要考虑歌曲的上传和播放.主要采取二进制的办法.
HttpPostedFile UpFile =this.File1.PostedFile; //HttpPostedFile对象,用于读取图象文件属性
FileLength = UpFile.ContentLength; //记录文件长度
try
{
if (FileLength == 0)
{ //文件长度为零时
this.lblInfo.Text = " <b> 请你选择你要上传的文件 </b> ";
}
else
{

Byte[] FileByteArray = new Byte[FileLength]; //图象文件临时储存Byte数组
Stream StreamObject = UpFile.InputStream; //建立数据流对像
//读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度
StreamObject.Read(FileByteArray,0,FileLength);
//建立SQL Server链接
SqlConnection Con = new SqlConnection( "uid=sa;pwd=19830517;initial catalog=SWFCXYL;data source=. ");
//String SqlCmd = "INSERT INTO ImageStore (ImageData, ImageContentType, ImageDescription, ImageSize) VALUES (@Image, @ContentType, @ImageDescription, @ImageSize) ";
string SqlCmd= "insert into song (username,accept,songname,songaddr,Content,songtype,songsize) values(@username,@accept,@songname,@songaddr,@Content,@songtype,@songsize) ";

SqlCommand CmdObj = new SqlCommand(SqlCmd, Con);
CmdObj.Parameters .Add ( "@username ",SqlDbType.VarChar ,20).Value=this.lblUserName.Text ;
CmdObj.Parameters .Add ( "@accept ",SqlDbType.VarChar ,20).Value=this.txtAcceptName.Text ;
CmdObj.Parameters .Add ( "@songname ",SqlDbType.VarChar ,50).Value=this.txtSongName.Text ;
CmdObj.Parameters.Add( "@songaddr ",SqlDbType.Binary, FileLength).Value = FileByteArray;
CmdObj.Parameters .Add ( "@Content ",SqlDbType.VarChar ,255).Value=this.txtRemark.Text ;

CmdObj.Parameters.Add( "@songtype ", SqlDbType.VarChar,50).Value = UpFile.ContentType; //记录文件类型
//把其它单表数据记录上传

//记录文件长度,读取时使用
CmdObj.Parameters.Add( "@songsize ", SqlDbType.Int).Value = UpFile.ContentLength;
Con.Open ();
CmdObj.ExecuteNonQuery();
Con.Close();
this.lblInfo.Text = " <p> <b> OK!你已经成功上传你的图像文件 </b> ";//提示上传成功


}
}
catch (Exception ex)
{
this.lblInfo.Text = ex.Message.ToString();
}