2010-07-04 6 views
1

Voici mon extrait:OpenFileDialog Control - Comment puis-je saisir le chemin sélectionné et l'afficher dans une zone de texte?

private void btnBrowseCInv_Click(object sender, EventArgs e) 
{ 
    ofdBrowseVInv.Title = "Locate Customer Invoice File"; 
    ofdBrowseVInv.Filter = "Portable Document Format (*.pdf)|*.pdf|All Files (*.*)|*.*"; 
    ofdBrowseVInv.FileName = ""; 
    ofdBrowseVInv.FilterIndex = 0; 

    ofdBrowseVInv.InitialDirectory = ""; 

    ofdBrowseVInv.CheckFileExists = true; 
    ofdBrowseVInv.CheckPathExists = true; 

    if (ofdBrowseVInv.ShowDialog() == System.Windows.Forms.DialogResult.OK) 
    { 
    //txtInvoicePathCInv.Text = ofdBrowseVInv... What property should i use? 
    } 
} 

Comme vous le voyez ci-dessous, une fois qu'un utilisateur de choisir un fichier et cliquez sur Ouvrir. Je veux que le chemin sélectionné s'affiche dans la zone de texte pointée nommée "txtInvoicePathCInv". Une idée?

J'utilise des applications Windows ...

alt text http://img708.imageshack.us/img708/54/99763211.jpg

+0

+1 points de style pour ajouter une capture d'écran! :) –

Répondre

1

Utilisez la propriété FileName:

txtInvoicePathCInv.Text = ofdBrowseVInv.FileName; 

Cela vous donnera tout le chemin, mais vous pouvez toujours utiliser la partie répertoire, en utilisant Path.GetDirectoryName:

txtInvoicePathCInv.Text = Path.GetDirectoryName(ofdBrowseVInv.FileName); 
1
string filename = System.IO.Path.GetFileName(ofdBrowseVInv.FileName); 
string path = System.IO.Path.GetDirectoryName(ofdBrowseVInv.FileName); 
Questions connexes