How to save files from folder in Database using C# in Windows Forms Application

Last Reply 3 months ago By AnandM

Posted 3 months ago

Anyone help me with this i know openfolderbrowser code required ..

Posted 3 months ago

Hi RanaAyaz,

Refer below sample code and modify it according to your need.


private void button1_Click(object sender, EventArgs e)
    string path = folderBrowserDialog1.SelectedPath;
    string[] files = Directory.GetFiles(path);
    StringBuilder str = new StringBuilder();
    foreach (string item in files)
        string fileName = item.Split('\\')[item.Split('\\').Length - 1];
        byte[] byteData = File.ReadAllBytes(item);
        // Insert Code with FileName and ByteData comes here.
        str.Append(fileName + Environment.NewLine);
    lblFileNames.Text = str.ToString();


Private Sub button1_Click(sender As Object, e As EventArgs)
	Dim path As String = folderBrowserDialog1.SelectedPath
	Dim files As String() = Directory.GetFiles(path)
	Dim str As New StringBuilder()
	For Each item As String In files
		Dim fileName As String = item.Split("\"C)(item.Split("\"C).Length - 1)
		Dim byteData As Byte() = File.ReadAllBytes(item)
		' Insert Code with FileName and ByteData comes here.
		str.Append(fileName + Environment.NewLine)
	lblFileNames.Text = str.ToString()
End Sub


I agree, here is the link: