Click here to Skip to main content
15,909,503 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

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.
 
Share this answer
 
Comments
Manisha Tambade 15-Mar-12 7:37am    
Thanks for suggestion.
Actually my purpose is to reduce image or any file (of big size) so that my uploading time will reduce.Hence i willing to do compress at client side only.is it possible?
PJ003 16-Mar-12 10:37am    
Try converting the file into binary format and then store it in database.
Rahul Rajat Singh 16-Mar-12 12:44pm    
and could you please tell me how can i convert file in binary at client side. and how will this binary conversion help in reducing the size?
C#
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 { }
                    }
                
            }



            }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900