Bonjour ,

J'ai une question toute bete.
J'ai créé un dormulaire qui consiste à créer, modifier et supprimer un fichier.
En local ça fctionne très bien.
Mais sur le site ça ne fonctionne pas très bien.
Pour faire la modification ça fctionne très bien. Il réussi à trouver le fichier et à faire la modif, mais pour créer et supprimer j'ai cette erreur :

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path '~/fluxRSS5.xml'.


ce que je ne comprends pas c'est pourquoi ça fctionne pour la modif et pas pour le reste alors que c pratiquement le même code (voir code en rouge):

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

    protected void ButtonClick_Modifier(object sender, EventArgs e) 
    {
        if (selectIndex == -1)
        {
            this.RegisterClientScriptBlock("alertmessage", "<script>alert('please select one modify data item.')</script>");
        }
        else
        {

                //on effectue les modifications dans ListeFluxRSS.xml ainsi que dans le fichier lui même.

                XmlDocument docListeFlux = new XmlDocument();
                docListeFlux.Load(Server.MapPath("ListeFluxRSS.xml"));


                XmlDocument docFichierRSS = new XmlDocument();
                string strpath = TextBoxNomFlux.Text;
                docFichierRSS.Load(Server.MapPath(strpath));                DateTime datNow = DateTime.Now;

                XmlNode xmlnodeListeFluxRSS = docListeFlux.DocumentElement.ChildNodes.Item(selectIndex);

                xmlnodeListeFluxRSS["title"].InnerText = this.TextBoxTitle.Text.Trim();
                xmlnodeListeFluxRSS["link"].InnerText = this.TextBoxLink.Text.Trim();
                xmlnodeListeFluxRSS["description"].InnerText = this.TextBoxDescription.Text.Trim();
                xmlnodeListeFluxRSS["webmaster"].InnerText = this.TextBoxWebMaster.Text.Trim();
                xmlnodeListeFluxRSS["publier"].InnerText = this.TextBoxPublier.Text.Trim();
                xmlnodeListeFluxRSS["date_last_modif"].InnerText = datNow.ToString();



                XmlNodeList listChildren = docFichierRSS.DocumentElement.LastChild.ChildNodes;

                //on parcours tous les elts qui décrivent le channel
                foreach (XmlNode noeud in listChildren)
                {

                    if (noeud.Name == "title")
                        noeud.InnerText = TextBoxTitle.Text;
                    if (noeud.Name == "link")
                        noeud.InnerText = TextBoxLink.Text;
                    if (noeud.Name == "description")
                        noeud.InnerText = TextBoxDescription.Text;


                }



                docListeFlux.Save(Server.MapPath("ListeFluxRSS.xml"));
                docFichierRSS.Save(Server.MapPath(strpath));

                loadXmlData();
                ButtonClick_Clear(sender, e);

            }
    }


    protected void ButtonClick_Supprimer(object sender, EventArgs e) 
    {

        XmlDocument docListeFlux = new XmlDocument();
        docListeFlux.Load(Server.MapPath("ListeFluxRSS.xml"));

        XmlNode xmlnode = docListeFlux.DocumentElement.ChildNodes.Item(selectIndex);

        string strpath = xmlnode["nomFlux"].InnerText;
        FileInfo fichierRSS = new FileInfo(strpath);
        fichierRSS.Delete();     
        xmlnode.ParentNode.RemoveChild(xmlnode); 
        docListeFlux.Save(Server.MapPath("ListeFluxRSS.xml"));
       
        loadXmlData();
        ButtonClick_Clear(sender, e);

    }


    protected void Button_AjoutFluxRSS(object sender, EventArgs e) 
    {        
        string strpath = TextBoxNomFlux.Text;
        FileInfo nouveauFluxRSS = new FileInfo(strpath);
        
        
       if(nouveauFluxRSS.Exists)
        {
            TextBoxNomFlux.Text = "";
        
        }

             else {

           //création du nouveau fichier
            XmlTextWriter newXmlFile = new XmlTextWriter(strpath, System.Text.Encoding.Default);
            newXmlFile.WriteStartDocument(true);			//creating the name of the main node			

            newXmlFile.WriteStartElement("rss");
            newXmlFile.WriteAttributeString("version", "2.0");

            newXmlFile.WriteStartElement("channel", "");
            newXmlFile.WriteElementString("title", TextBoxTitle.Text);
            newXmlFile.WriteElementString("link", TextBoxLink.Text);
            newXmlFile.WriteElementString("description", TextBoxDescription.Text);
            newXmlFile.WriteElementString("webmaster", TextBoxWebMaster.Text);

            //sauvegarde des données dans le fichier XML.
            newXmlFile.WriteEndElement();
            newXmlFile.WriteEndElement();
            newXmlFile.Flush();
            newXmlFile.Close();


            //mise à jour du fichier ListeFluxRSS.xml
            XmlDocument docFluxRSS = new XmlDocument();
            docFluxRSS.Load(Server.MapPath("ListeFluxRSS.xml"));

            XmlElement parentNode = docFluxRSS.CreateElement("flux");
            docFluxRSS.DocumentElement.AppendChild(parentNode);

            XmlElement nomFluxNode = docFluxRSS.CreateElement("nomFlux");
            XmlElement titreNode = docFluxRSS.CreateElement("title");
            XmlElement linkNode = docFluxRSS.CreateElement("link");
            XmlElement descriptionNode = docFluxRSS.CreateElement("description");
            XmlElement webmasterNode = docFluxRSS.CreateElement("webmaster");
            XmlElement publierNode = docFluxRSS.CreateElement("publier");
            XmlElement dateLastModifNode = docFluxRSS.CreateElement("date_last_modif");

            DateTime datNow = DateTime.Now;

            XmlText nomFluxText = docFluxRSS.CreateTextNode(TextBoxNomFlux.Text);
            XmlText titreText = docFluxRSS.CreateTextNode(TextBoxTitle.Text);
            XmlText linkText = docFluxRSS.CreateTextNode(TextBoxLink.Text);
            XmlText descriptionText = docFluxRSS.CreateTextNode(TextBoxDescription.Text);
            XmlText webmasterText = docFluxRSS.CreateTextNode(TextBoxWebMaster.Text);
            XmlText publierText = docFluxRSS.CreateTextNode(TextBoxPublier.Text);
            XmlText dateLastModifText = docFluxRSS.CreateTextNode(datNow.ToString());

            parentNode.AppendChild(nomFluxNode);
            parentNode.AppendChild(titreNode);
            parentNode.AppendChild(linkNode);
            parentNode.AppendChild(descriptionNode);
            parentNode.AppendChild(webmasterNode);
            parentNode.AppendChild(publierNode);
            parentNode.AppendChild(dateLastModifNode);

            nomFluxNode.AppendChild(nomFluxText);
            titreNode.AppendChild(titreText);
            linkNode.AppendChild(linkText);
            descriptionNode.AppendChild(descriptionText);
            webmasterNode.AppendChild(webmasterText);
            publierNode.AppendChild(publierText);
            dateLastModifNode.AppendChild(dateLastModifText);

            docFluxRSS.Save(Server.MapPath("ListeFluxRSS.xml"));
            loadXmlData();
            ButtonClick_Clear(sender, e);
        } 

    }