User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 375,194 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,174 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 2681 | Replies: 85 | Solved
Reply
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,122
Reputation: majestic0110 is on a distinguished road 
Rep Power: 3
Solved Threads: 47
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Veteran Poster

Re: Last q on this project I promise lol

  #31  
Feb 6th, 2008
right ok, I am not sure where to put that code and do I have to declare newsavedfile as the file I just uploaded?
Reply With Quote  
Join Date: Sep 2007
Posts: 1,054
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Last q on this project I promise lol

  #32  
Feb 6th, 2008
newsavedfile should be the file path of your newly saved file. Then, when you are done with all your code, put that there so it automatically has them download it.
Reply With Quote  
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,122
Reputation: majestic0110 is on a distinguished road 
Rep Power: 3
Solved Threads: 47
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Veteran Poster

Re: Last q on this project I promise lol

  #33  
Feb 6th, 2008
do you mean
XPathDocument doc = new XPathDocument(Server.MapPath("C:/temp/" + FileUpload1.FileName));
instead use
server.transfer(server.mappath(newsavedfile)
)

I dont really understand
Last edited by majestic0110 : Feb 6th, 2008 at 10:12 am.
Reply With Quote  
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,122
Reputation: majestic0110 is on a distinguished road 
Rep Power: 3
Solved Threads: 47
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Veteran Poster

Re: Last q on this project I promise lol

  #34  
Feb 6th, 2008
it would be very good if the user auto downloaded the files to a predefined folder(created if not existing) without the user having to click a button if you know what I mean. But then there are security issuesI guess
Reply With Quote  
Join Date: Sep 2007
Posts: 1,054
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Last q on this project I promise lol

  #35  
Feb 6th, 2008
Yes you won't be able to do that.

No, what I mean is that after you are done saving and formatting the XML document, compeletely done with it, add that code there, or in your case:

Server.Transfer("C:/temp/" + FileUpload1.FileName)

That should basically be your last line of code after converting everything.
Reply With Quote  
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,122
Reputation: majestic0110 is on a distinguished road 
Rep Power: 3
Solved Threads: 47
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Veteran Poster

Re: Last q on this project I promise lol

  #36  
Feb 6th, 2008
hmmm. Having done that, getting runtime exception of "expected virtual path"
I put that line right before the return strHtml statement at bottom of code.lol this is my first asp.net app - talk about jumping in at deep end !
Last edited by majestic0110 : Feb 6th, 2008 at 10:41 am. Reason: missed a bit out
Reply With Quote  
Join Date: Sep 2007
Posts: 1,054
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Last q on this project I promise lol

  #37  
Feb 6th, 2008
You are receiving that error on the code "C:/..."? That's odd, but okay. So put the server.mappath("") relative to your document. If your document is in C:/documents/asppage.aspx then put something like this:

server.transfer(server.mappath("../temp/" & FileUpload1.FileName))

Oh, and keep in mind that if "filename" is only the name, you will have to add ".xml" at the end. Spit out (server.mappath("../temp/" & FileUpload1.FileName)) to see if it is displaying correctly. (put it in a response.write)
Reply With Quote  
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,122
Reputation: majestic0110 is on a distinguished road 
Rep Power: 3
Solved Threads: 47
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Veteran Poster

Re: Last q on this project I promise lol

  #38  
Feb 6th, 2008
its still throwing that exception when I change it to server.transfer(server.mappath("../temp/" & FileUpload1.FileName))
Reply With Quote  
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,122
Reputation: majestic0110 is on a distinguished road 
Rep Power: 3
Solved Threads: 47
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Veteran Poster

Re: Last q on this project I promise lol

  #39  
Feb 6th, 2008
OK here is what I currently have
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
using System.IO;


namespace runXslt { }

public partial class Default2 : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        // Specify the path on the server to
        // save the uploaded file to.
        String savePath = "C:/temp/";     

        // Get the name of the file to upload.
        String fileName = FileUpload1.FileName;

        // Get the extension of the uploaded file.
        string extension = System.IO.Path.GetExtension(fileName);

        // Before attempting to perform operations
        // on the file, verify that the FileUpload 
        // control contains a file.
        if (FileUpload1.HasFile)
        {
            if ((extension == ".xml"))
            {                     
                // Append the name of the file to upload to the path.
                savePath += fileName;
                               
                // Call the SaveAs method to save the 
                // uploaded file to the specified path.
                // If a file with the same name
                // already exists in the specified path,  
                // the uploaded file overwrites it.
                FileUpload1.SaveAs(savePath);
           
                // Notify the user of the name of the newly saved file
                Label1.Text = "SUCCESS! - Your file was uploaded and converted as " + fileName;
                

                //call XSLT transform
                ApplyXSLTransformation();
            }

            else
            {
                // Notify the user why their file was not uploaded.
                Label1.Text = "ERROR - Your file was not uploaded or converted because " + 
                    fileName + "it does not have a .xml extension.";

            }
        }

        else
        {
            // Notify the user that a file was not uploaded.
            Label1.Text = "ERROR - You did not specify a file to upload.";
        }
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {

    }

    private string ApplyXSLTransformation()
    {
        string strHtml;

        string strXstFile = Server.MapPath("test.xslt");
        XslCompiledTransform x = new XslCompiledTransform();

        // Load the XML - use (Server.MapPath("/temp/" + FileUpload1.FileName));
        //if using server i.e. not local machine
        XPathDocument doc = new XPathDocument(("C:/temp/" + FileUpload1.FileName));

        // Load the style sheet.
        XslCompiledTransform xslt = new XslCompiledTransform();
        xslt.Load(strXstFile);
        MemoryStream ms = new MemoryStream();
        XmlTextWriter writer = new XmlTextWriter(ms, null);
        StreamReader rd = new StreamReader(ms);
        xslt.Transform(doc, writer);
        ms.Position = 0;
        strHtml = rd.ReadToEnd();
        rd.Close();
        ms.Close();
        Server.Transfer(Server.MapPath("C:/temp/dl" + FileUpload1.FileName));
        return strHtml;
       
    }
}
Last edited by majestic0110 : Feb 6th, 2008 at 11:18 am. Reason: highlight area of interest
Reply With Quote  
Join Date: Sep 2007
Posts: 1,054
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Last q on this project I promise lol

  #40  
Feb 6th, 2008
try specifying the name of the file. server.transfer may not allow transfering to a XML file, you know? It may only except .net extensions.'

You can try response.redirect instead, or build a "thank you" page with the download link where they can download the file. Then they can click and download it when they are ready.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ASP.NET Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 2:09 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC