Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nigel 29 posts 52 karma points
    Jul 16, 2013 @ 16:22
    Nigel
    0

    Issue with Querystring Value

    Hi,

    Great extension however I can't seem to get it working. (in that it isn't getting the querystring value)

    I've tried recompling the extension using  the bin files for 6.1.1. and adding

                Response.Write("<br/>Host: " + HttpContext.Current.Request.Url.Host);
                Response.Write("<br/>Authority: " + HttpContext.Current.Request.Url.Authority);
                Response.Write("<br/>AbsolutePath: " + HttpContext.Current.Request.Url.AbsolutePath);
                Response.Write("<br/>ApplicationPath: " + HttpContext.Current.Request.ApplicationPath);
                Response.Write("<br/>Host: " + HttpContext.Current.Request.Url.Host);
                Response.Write("<br/>AbsoluteUri: " + HttpContext.Current.Request.Url.AbsoluteUri);
                Response.Write("<br/>PathAndQuery: " + HttpContext.Current.Request.Url.PathAndQuery);

    to he ascx.cs file but it only returns the following when the url is http://localhost:40145/client-area/downloads/?file=testfile

    Host: localhost
    Authority: localhost:40145
    AbsolutePath: /client-area/downloads/
    ApplicationPath: /
    Host: localhost
    AbsoluteUri: http://localhost:40145/client-area/downloads/
    PathAndQuery: /client-area/downloads/

    I don't have any redirects and I can't see any other issue. Is it possible to pass the 'file' value as a parameter?

    Many thanks

     

     

     

     

     

  • Simon steed 376 posts 688 karma points
    Jul 16, 2013 @ 20:55
    Simon steed
    0

    Hi Nigel

    Thanks :-) Not used it for a while myself and certainly not with v6 - i'll try and get the code out tonight and see if there is any reason why it wouldnt work and let you know what I find out

    Concept is really simple and i've used the code on 4.10.8 projects with no issues so should be something simple - I hope!

    Simon

  • Simon steed 376 posts 688 karma points
    Jul 16, 2013 @ 21:40
    Simon steed
    0

    Hi Nigel

    Sorted it - didnt realise the package wasnt setting up the environment properly so unless you could work out how to use it, you wouldnt get it working - h5is!

    OK i'm about to upload a complete working example running a v6.1.2 site - you will see the following:

    1. Standard starter kit
    2. Package is installed
    3. I've recompiled with v6 dlls - was not really needed but did it anyway
    4. Setup a folder with a file in it - you need to update the file path in the Local Filepath section of the files.
    5. Note you can have multiple files - they live as nodes under the Your Account page.
    6. Your Account must be named as such, rename it and you need to modify ListDownloads.xslt to suit

    Thats about it - the site is configured to run SQL CE so literally point to a folder in IIS and run. Click on the file download and it should just work!

    Just going to zip it all up and upload now

    Thanks

    Si

  • Nigel 29 posts 52 karma points
    Jul 17, 2013 @ 09:38
    Nigel
    0

    Many thanks Simon.

    I should have just waited for you to do your magic.

    However I made some changes yesterday which you can add to your version if applicable.

    *****************

    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 umbraco.NodeFactory;
    //using umbraco.presentation.nodeFactory; //Obsol


    namespace simonantony.uSecureFiles
    {
      
       
        public partial class FileDownloadControl : System.Web.UI.UserControl
        {

            protected void Page_Load(object sender, EventArgs e)
            {


                /*
                Response.Write("<br/>Host " + HttpContext.Current.Request.Url.Host);
                Response.Write("<br/>Authority " + HttpContext.Current.Request.Url.Authority);
                Response.Write("<br/>AbsolutePath " + HttpContext.Current.Request.Url.AbsolutePath);
                Response.Write("<br/>ApplicationPath " + HttpContext.Current.Request.ApplicationPath);
                Response.Write("<br/>Host " + HttpContext.Current.Request.Url.Host);
                Response.Write("<br/>AbsoluteUri " + HttpContext.Current.Request.Url.AbsoluteUri);
                Response.Write("<br/>PathAndQuery " + HttpContext.Current.Request.Url.PathAndQuery);
                Response.Write("<br/>Query " + HttpContext.Current.Request.QueryString["file"]);
                */

                if (!IsPostBack)
                {

                    if (Request.QueryString["file"] != null || Session["file"] != null)
                    {
                        if (Session["file"] != null)
                        {
                            ServeFile(Session["file"].ToString());
                        }
                        if (Request.QueryString["file"] != null)
                        {
                            ServeFile(Request.QueryString["file"].ToString());
                        }
                    }
                }
            }

            private void ServeFile(string FileName)
            {
                try
                {

                    // get requested filename then loop through using umbraco.presentation.nodeFactory to find the parent
                    Node myNode = Node.GetCurrent();
                    Nodes childrenNodes = myNode.Children;

                    //int currentNodeId = umbraco.presentation.UmbracoContext.Current.PageId.Value; // parent node id
                    //umbraco.presentation.nodeFactory.Node node = new umbraco.presentation.nodeFactory.Node(currentNodeId);
                    //umbraco.presentation.nodeFactory.Nodes childrenNodes = node.Children;


                    string strFileName = string.Empty;

                    // when we have the parent, we can get the real filename thenb pass it into strFileName
                        for (int i = 0; i < childrenNodes.Count; i++)
                        {
                            try
                            {

                                if (FileName.ToLower() == childrenNodes[i].GetProperty("downloadPackage").Value.ToString().ToLower())
                                {
                                    strFileName = childrenNodes[i].GetProperty("localFilepath").Value.ToString();

                                    break;
                                }
                            }
                            catch { }
                        }


                    string strFileExtension = Path.GetExtension(strFileName);

                    FileInfo fInfo = new FileInfo(strFileName);
                    Response.Clear();
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + MakeSafeFileName(Path.GetFileName(strFileName)));
                    Response.AddHeader("Content-Length", fInfo.Length.ToString());
                    switch (strFileExtension)
                    {
                        case ".pdf":
                            Response.ContentType = "application/pdf";
                            break;
                        case ".zip":
                            Response.ContentType = "application/zip";
                            break;
                        case ".exe":
                            Response.ContentType = "application/exe";
                            break;
                        case ".msi":
                            Response.ContentType = "application/msi";
                            break;
                        case ".doc":
                            Response.ContentType = "application/ms-word";
                            break;
                        case ".docx":
                            Response.ContentType = "application/ms-word";
                            break;
                        case ".xls":
                            Response.ContentType = "application/vnd.xls";
                            break;
                        case ".xlsx":
                            Response.ContentType = "application/vnd.xls";
                            break;
                        default:
                            Response.ContentType = "application/octet-stream";
                            break;     
                    }

                    Response.WriteFile(Server.MapPath(strFileName));    
                    Response.Flush();
                    Response.End();

                }
                catch (FileNotFoundException fnfex)
                {
                    Console.WriteLine(fnfex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }

            private string MakeSafeFileName(string orig)
            {
                return orig.Replace(" ", "-");
            }

        }
    }

     

     

     

  • Simon steed 376 posts 688 karma points
    Jul 30, 2013 @ 10:45
    Simon steed
    0

    Thanks Nigel

    Looks good. I'll try and get them added into the core and repost at some point!

    Si

Please Sign in or register to post replies

Write your reply to:

Draft