Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

OpenFileDialog.Filter Error

$
0
0
               

Since FIlter types are maintained Database i am trying to set the OpenFileDialog.Filter proprty value to dynamically from database.
but unfortunately i am getting beolw error


Error:


Filter string you provided is not valid. The filter string must contain a description of the filter, followed by the vertical bar (|) and the filter pattern.
 The strings for different filtering options must also be separated by the vertical bar. Example: "Text files (*.txt)|*.txt|All files (*.*)|*.*"




below code is working fine with out issues if i set the Filter proprty like below 


    FileOpenDlg.Filter = "All Files (*.*)|*.*|" +"Adobe Files (*.pdf)|*.pdf|" +"Excel Files (*.xls)|*.xls|" +"Image Files (*.jpg; *.png; *.tif)|*.jpg;*.png;*.tif|" +"Power Point Files (*.ppt)|*.ppt|" +"Text Files (*.txt)|*.txt|" +"Visio Files (*.vsd)|*.vsd|" +"Word Document Files (*.doc)|*.doc|" +"Message Format (*.msg)|*.msg";





Below Code is throwing error where i am setting FileOpenDlg.Filter property dynamically from database

                                                                                                     


void opendialogTest()

{

    OpenFileDialog FileOpenDlg = new OpenFileDialog();


    FileOpenDlg.Title = "Please select a file(s) to add.";
    FileOpenDlg.InitialDirectory = "c:\\";



    DataTable validFileTypes = GetfileTypeData();


    string finalString = string.Empty;

    if (validFileTypes.Rows.Count > 0)
    {

    foreach (DataRow dealAttachType in validFileTypes.Rows)
    {


        finalString = finalString  + dealAttachType["ExtensionType"].ToString();


    }


    FileOpenDlg.Filter = finalString; ----- Here Throwing error


    if (DialogResult.OK == FileOpenDlg.ShowDialog(this))
    {
    // Neccesary Code
    }

}

private DataTable GetfileTypeData()
{   //THis is sample data ...but i need to get data from Database

var table = new DataTable();

table.Columns.Add("ID", typeof(int));
table.Columns.Add("ApplicationType", typeof(string));
table.Columns.Add("ExtensionType", typeof(string));
table.Columns.Add("IsAllowed", typeof(bool));


table.Rows.Add(1, "Allfiles", "All Files (*.*)|*.*|", true);

table.Rows.Add(2, "pdf files", "Adobe Files (*.pdf)|*.pdf|", true);
table.Rows.Add(3, "Excel Files", "Excel Files (*.xls)|*.xls|", true);

table.Rows.Add(4, "ImageFiles", "Image Files (*.jpg; *.png; *.tif)|*.jpg;*.png;*.tif|", true);

table.Rows.Add(5, "TextFiles", "Text Files (*.txt)|*.txt|", true);

table.Rows.Add(6, "Allfiles", "All Files (*.*)|*.*|", true);

return table;
}


In Both the situations FIlter value is same is showing in debugging mode but throwing error when i set dyanamic FinalString value.

what i am missinh here ,please help me .






                                                                                

Ramesh




Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>