1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Windows.Forms;
using System.IO;
namespace MXML
{
public partial class _Default : System.Web.UI.Page
{
[STAThread]
static void Main(string[] args)
{ }
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LoadXML_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Ouvrir un fichier de type XML";
ofd.Multiselect = false; //valeur par défaut
ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
/* La propriété suivante est un peu plus complexe.
* Chaque extension ou groupe d'extension fonctionne toujours par pair :
* la 1ere partie est ce que l'utilisateur pourra voir dans la boîte, la
* 2e est le filtre que la boîte va utiliser pour trier l'affichage des
* fichiers. Ces 2 groupes sont séparés par le caractère pipe ( | ). Vous pouvez
* ajouter autant de filtres que vous le voulez. */
ofd.Filter = "Fichiers XML(*.xml) | *.xml| Fichiers HTML (*.html; *.htm) | *.html; *.htm| Tous les fichiers (*.xml; *.html; *.htm) | *.xml; *.html; *.htm";
ofd.FilterIndex = 2; //valeur par défaut. L'index commence à partir de 1
ofd.ShowHelp = false; //valeur par défaut
ofd.ReadOnlyChecked = false; //valeur par défaut
ofd.ShowReadOnly = false; //valeur par défaut
//ShowDialog retourne un DialogResult
if (ofd.ShowDialog() == DialogResult.OK)
{
//Parce qu'il n'y a qu'un seul fichier qui a pu être sélectionné
string filename = ofd.FileName;
//Sinon on aurait du faire
//string[] files = ofd.FileNames;
//Traitement
}
}
}
} |