关于文件上传和视频上传的问题 [英] Problem Regarding File upload and video upload

查看:76
本文介绍了关于文件上传和视频上传的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有用于文件上传的代码(1)和用于视频上传的代码(2),但它们都只存储小文件,当转换为大文件时,它不存储,并给我连接错误"帮助我出去的朋友.

1):

i have code (1) for file upload and code (2) for video upload but both of them only store small files, when it turns to larger files it doesn''t store and gives me "connection error" help me out friends.

1):

if (FileUpload1.HasFile)
       {
           string Path = ConfigurationManager.AppSettings["UPLOAD_PATH"];
           FileUpload1.SaveAs(Path + FileUpload1.FileName);
           FileInfo file = new FileInfo(Path + FileUpload1.FileName);
           con.Open();
           Int64 userid = Convert.ToInt64(Session["LOGED_IN_USER"]);
           cmd = new SqlCommand(string.Format("INSERT INTO SHARED_FILES VALUES('{0}','{1}','{2}','{3}',CONVERT(VARCHAR(10),'{4}',110),'{5}')", FileUpload1.FileName, file.Length, file.FullName, userid, DateTime.Now.ToShortDateString(), txtkeyword.Text), con);
           cmd.ExecuteNonQuery();
           con.Close();

       }



2):



2):

byte[] buffer;//this is the array of bytes which will hold the data (file)
    SqlConnection connection;
    protected void ButtonUpload_Click(object sender, EventArgs e)
    {

        {
            //check the file
            if (FileUpload1.HasFile && FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
            {
                HttpPostedFile file = FileUpload1.PostedFile;
                buffer = new byte[file.ContentLength];
                int bytesReaded = file.InputStream.Read(buffer,0,FileUpload1.PostedFile.ContentLength);
                
                if (bytesReaded > 0)
                {
                    try
                    {
                        string connectionString = ConfigurationManager.ConnectionStrings["FreelancingConnectionString"].ConnectionString;
                        connection = new SqlConnection(connectionString);
                        SqlCommand cmd = new SqlCommand
                            ("INSERT INTO SHARED_VIDEOS (VIDEO, VIDEO_NAME, VIDEO_SIZE, DATE_ADDED) VALUES (@video, @videoName, @videoSize, @dateAdded)", connection);
                        cmd.Parameters.Add("@video", SqlDbType.VarBinary, buffer.Length).Value = buffer;
                        cmd.Parameters.Add("@videoName", SqlDbType.NVarChar).Value = FileUpload1.FileName;
                        cmd.Parameters.Add("@videoSize", SqlDbType.BigInt).Value = file.ContentLength;
                        cmd.Parameters.Add("@dateAdded", SqlDbType.DateTime).Value = DateTime.Now;
                        using (connection)
                        {
                            connection.Open();
                            int i = cmd.ExecuteNonQuery();
                            Label1.Text = "uploaded, " + i.ToString() + " rows affected";
                            Label1.ForeColor = System.Drawing.Color.LightGreen;
                        }
                    }
                    catch (Exception ex)
                    {
                        Label1.Text = ex.Message.ToString();
                    }
                }

推荐答案

阿萨德

当您在C#中使用asp.net文件上传控件时,它在大小上有一些限制.
因此最好使用第三方文件上传控件.

您可以在这里找到免费的开源控件:

使用进度条使用Flash和ASP.NET进行多个文件上传 [
Hi, Asad

When ur using asp.net file upload control in c# it have some limitations on size.
so it''s better to go for third party file upload controls.

The Free open source control u will find here:

Multiple File Upload With Progress Bar Using Flash and ASP.NET[^]

It''s working for me let me know if u have any query''s

Thanks....


这篇关于关于文件上传和视频上传的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆