在Asp.net中上传之前进行文件压缩 [英] File compression before uploading in Asp.net

查看:85
本文介绍了在Asp.net中上传之前进行文件压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
有谁能在使用asp.net将文件上传到服务器之前知道如何压缩任何类型的文件?如果是的话,代码将如何.
由于我在Google上进行搜索,因此我在上传后找到了-压缩.
请帮助任何解决方案..
在此先感谢您.

hi all,
can anybody know how to compress any type of file before uploading on server using asp.net.Will is be possible? if it is then how will be code.
Since i searched on google i found there As after uploading - compress.
plz. help any solution..
Thanks in advance.

推荐答案

在上传之前,这意味着您要在客户端执行此操作.将这样的代码放在客户端会给用户带来一定的限制.理想情况下,这应该在服务器端完成,因此请确保所有依赖性(服务器上存在用于压缩的任何方法).

如果您想给出压缩是在上载之前进行的错觉,那么也许一些Ajax可能会有所帮助.
before uploading would mean you want to do that on client side. Putting such a code on client side will impose certain constraints on the users. ideally this should be done on server side so ensure all the dependencies(for whatever method you use for compression are present on server).

If you want to give the illusion that the compression is happening before upload then perhaps some Ajax could help.


SQL Procedure 

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE UploadFile
        @filename varchar(max),

AS 

 
                    
                  BEGIN 
                          
                          INSERT INTO Table_Name(Uploaded_File) 
                          VALUES ((CONVERT(varbinary (max),@filename))) 
 
                          
                  END              


GO


Asp Code

        private void btnUpload_Click(object sender, EventArgs e)
        {
            if(tbxFileName.Text.Length == 0)
            {
                MessageBox.Show("Please select a file to upload.");
            }
            else
            {
               
                    
                    using (SqlConnection sqlConn = new SqlConnection(connectionString))
                    {
                        SqlCommand cmd = new SqlCommand();
                        cmd.Parameters.Add("@filename", SqlDbType.VarChar,200000).Value = text;
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "UploadFile";
                        cmd.Connection = sqlConn;
                        cmd.Connection.Open();
                        tbxname.Clear();
                        tbxfilepath.Clear();
                        try
                        {
                            cmd.ExecuteNonQuery();
                        }
                        catch { }
                    }
                
            }



            }


这篇关于在Asp.net中上传之前进行文件压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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