Click here to Skip to main content
15,904,655 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want open in xml file when i upload the file
plz any one send the code


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Xml;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUploadControl.HasFile)
        {
            try
            {
                if (FileUploadControl.PostedFile.ContentType == "My Documents")
                {
                    if (FileUploadControl.PostedFile.ContentLength < 102400)
                    {
                        string filename = Path.GetFileName(FileUploadControl.FileName);
                        FileUploadControl.SaveAs(Server.MapPath("C:\\Documents and Settings\\azhar\\My Documents\\flashrecorder.xml") + filename);
                        Label1.Text = "Upload status: File uploaded!";
                    }
                    else
                        Label1.Text = "Upload status: The file has to be less than 100 kb!";
                }
                else
                    Label1.Text = "Upload status: Files are accepted!";
            }
            catch (Exception ex)
            {
                Label1.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
            }
        }
    }
}
Posted
Comments
AmitGajjar 24-Feb-12 7:04am    
Bad Practice : do not hardcode xml file path. instead create temporary directory and store your xml in it.

1 solution

C#
if (FileUploadControl.HasFile)
       {
           try
           {
               if (FileUploadControl.PostedFile.ContentType == "My Documents")
               {
                   if (FileUploadControl.PostedFile.ContentLength < 102400)
                   {
                       string filename = Path.GetFileName(FileUploadControl.FileName);
                       FileUploadControl.SaveAs(Server.MapPath("C:\\Documents and Settings\\azhar\\My Documents\\flashrecorder.xml") + filename);
                       Label1.Text = "Upload status: File uploaded!";

Response.Redirect(Server.MapPath("C:\\Documents and Settings\\azhar\\My Documents\\flashrecorder.xml
           "        }
                   else
                       Label1.Text = "Upload status: The file has to be less than 100 kb!";
               }
               else
                   Label1.Text = "Upload status: Files are accepted!";
           }
           catch (Exception ex)
           {
               Label1.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
           }
       }
 
Share this answer
 
Comments
AmitGajjar 24-Feb-12 7:13am    
if you hare redirected your page then you do not need to set Label1.Text information.
rockpune 24-Feb-12 7:42am    
am not getting output as xml file how can i see that file as xml
AmitGajjar 24-Feb-12 7:49am    
you mean to say, you want to see XML nodes ?
rockpune 25-Feb-12 1:12am    
yes sir

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900