Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
types of files: pdf,word,video,audio

I have uploaded files. i want my file should be in encrypted format.unreadable format.
C#
protected void UploadFileToSharePoint(string UploadedFilePath, string SharePointPath)

        {
            WebResponse response = null;
           
            try
            {
                // Create a PUT Web request to upload the file.
                WebRequest request = WebRequest.Create(SharePointPath);
                File.Encrypt(SharePointPath);
                request.Credentials = CredentialCache.DefaultCredentials;

                request.Method = "PUT";

                // Allocate a 1 KB buffer to transfer the file contents.
                // You can adjust the buffer size as needed, depending on
                // the number and size of files being uploaded.
                byte[] buffer = new byte[1024];

                // Write the contents of the local file to the
                // request stream.
                using (Stream stream = request.GetRequestStream())
                using (FileStream fsWorkbook = File.Open(UploadedFilePath,
                    FileMode.Open, FileAccess.Read))
                {
                    int i = fsWorkbook.Read(buffer, 0, buffer.Length);

                    while (i > 0)
                    {
                        
                        stream.Write(buffer, 0, i);
                        i = fsWorkbook.Read(buffer, 0, buffer.Length);
                    }
                }

                // Make the PUT request.
                response = request.GetResponse();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                response.Close();
            }
        }
Posted
Updated 12-Aug-12 18:28pm
v3
Comments
Sergey Alexandrovich Kryukov 13-Aug-12 0:31am    
Not a question. "Encrypted" and "unreadable" are different things, but encrypted files are not readable. However, you need to explain the scenario; where do you want to store and use the key for decryption, otherwise, if you can decrypt the file, anyone can. You can open-key encryption, but you need to figure out how to distribute the keys. To explain it to you, I would need to know your purpose and required scenario (requirements). Or read about encryption (.NET provide good set of implementations) and figure out by yourself.
--SA

1 solution

.NET already provides the ability to encrypt files. You could look at this MSDN article which explains how to achieve that:
http://support.microsoft.com/kb/307010/en-us[^]
 
Share this answer
 
Comments
oliver grace 16-Aug-12 1:00am    
this url works fine when encrypt my file.when i decrypt my file getting error like bad data.

error:
System.Security.Cryptography.CryptographicException: Bad Data.

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