Click here to Skip to main content
15,915,336 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi ,

Any one can give me a example how can we encyrpt selcted files in gridview and save them in certain folder, i have tried below code but cant encrypt selected file.

What I have tried:

<pre>void BtnUploadClick(object sender, EventArgs e)
        {
            //Sample on Sun 01.12.2014 At 09.13 AM
            string locationToCreateFolder = "E://";
            string folderName = "Upload";
            string date = DateTime.Now.ToString("ddd MM.dd.yyyy");
            string time = DateTime.Now.ToString("HH.mm tt");
            string format = "{0} on {1} At {2}";
            folderName = string.Format(format, textBox1.Text, date, time);
            Directory.CreateDirectory(locationToCreateFolder + "Upload");
            MessageBox.Show("done");
            int CheckBoxRowCounter = 0;
            // Encrypt_and_decrypt.AES a  = new AES();
            for (int i = 0; i < dataGridView1.RowCount; i++)
            {
                if (Convert.ToBoolean(dataGridView1.Rows[i].Cells[0].Value))
                {
                    CheckBoxRowCounter++;
                }
            }
             if (CheckBoxRowCounter > 0)
            {
                if (folderBrowserDlg.ShowDialog() == DialogResult.OK)
                {
                    String folderPath = folderBrowserDlg.SelectedPath;
                    for (int i = 0; i < dataGridView1.RowCount; i++)
                    {
                        if (Convert.ToBoolean(dataGridView1.Rows[i].Cells[0].Value))
                        {
                            string SourceFilePath = dataGridView1.Rows[i].Cells[1].Value.ToString();
                            string SourceFileName = new System.IO.FileInfo(SourceFilePath).Name;
                            string TargetFilePath = folderPath + @"\" + SourceFileName;
                            if (!System.IO.File.Exists(TargetFilePath))
                            {
                                if (System.IO.File.Exists(SourceFilePath))
                                {
                                    System.IO.File.Move(SourceFilePath, TargetFilePath);
                                }
                            }
                            //string Hidkey = dataGridView1[0,2].Value.ToString();
                        //    dataGridView1[0,1].Value= a.EncryptFile("E:\\ on Fri 05.11.2018 At 08.59 AM","E:\\encrypt","Hidkey");
                        }
                    }
                    MessageBox.Show("Selected Files Moved.Refreshing Grid...");
                    FillGridView();
                }
            }
Posted
Updated 10-May-18 22:56pm

This is your second repost of this question and you have been given a number of suggestions. Maybe you should try some of them.
 
Share this answer
 
There's a whole Cryptography namespace in .NET. To encrypt your files, you need to write code to encrypt them, which you have not, yet. Why would you have a web app that takes a path on the client and then iterates over that folder on the server? If you want to write code to let people manage your file system, you'll need to tell them what it is
 
Share this answer
 
Comments
Member 13818142 11-May-18 0:54am    
I have already written a code for encrypting files i am calling them in the button click, what actually i need is when i click on button i will be selecting(checking) some files in grid view, the selected files need to be encrypted and move to a folder in local system.
I all thanks for your suggestions, I have got my solution.but I need one suggestion
I have written belw code on button click where it creates a folder when i click on button, and in my orginal post i upload files through folderbrowser tool, now i need to uplaod files dirctly with out using it how can i do it.
void BtnUploadClick(object sender, EventArgs e)
		{
			 var folder =Directory.CreateDirectory("E:\\UPLOAD");

}
 
Share this answer
 
Comments
Richard MacCutchan 11-May-18 5:26am    
FolderBrowser is a dialog to find a folder name. It has nothing to do with actually processing the files.
Richard Deeming 11-May-18 9:37am    
How is this supposed to be a "solution" to your question?

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