Tilde in UploadServiceUrl ignores virtual dir

24 posts, 0 answers
  1. Anders
    Anders avatar
    2 posts
    Member since:
    Jun 2010

    Posted 25 Jun 2010 Link to this post

    Hi

    The UploadServiceUrl property in RadUpload for Silverlight 4 seems to always resolve the ~ (tilde) to the root of the web site, not the root of the application, as is the behaviour in .net. Is this a bug?

    Example:

    I would expect an application running on virtual path "MyVirtualDir" on localhost to resolve the ~ like this:

    If i set property UploadServiceUrl="~/MyHandler.ashx", the resulting URL should be:
    http://localhost/MyVirtualDir/MyHandler.ashx

    However, the follwing seems to be the result:
    http://localhost/MyHandler.ashx

    King regards,
    Anders
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 01 Jul 2010 Link to this post

    Hello Anders,

    Please accept my apology for the delayed response.

    The scenario you described - using a Virtual Directory is not supported in the RadUpload since the path for the UploadHandler is specified and resolved on the client side. On the client side the virtual directories created on the server side cannot be determined.  Therefore in cases that this path is specified using ~(tilde) - UploadServiceUrl="~/SampleUploadHandler.ashx" the tilde is ignored thus returning the same URL returned by UploadServiceUrl="/SampleUploadHandler.ashx".

    Please let us know if you need more info.

    Greetings,
    Tina Stancheva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. rob mays
    rob mays avatar
    58 posts
    Member since:
    Jun 2007

    Posted 13 Sep 2010 Link to this post

    is there an example on how to use the UploadServiceUrl, I am trying to use the radUpload to upload an .xls in silverlight 4. I want to process the uploaded .xls file so as I can add the rows to my Sql Datatable please? then let the user know the file was processed successfully?
  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 16 Sep 2010 Link to this post

    Hello rob mays,

    I attached an example demonstrating how you can upload images into a database using RadUpload. This example will help you in implementing your scenario. It illustrates how to process uploaded image files on the server-side by overriding the SaveChunkData() method of the RadUploadHandler to process the images and save them into a database. In your case, however, instead of processing the images you can write some custom logic to process the xls files. Also, please keep in mind that in the example a filter is applied to the RadUpload in order to allow uploading only image files so you will need to modify the RadUpload Filter property as well to fit your requirements.

    Once the files are processed and saved into a database, you can create a bool property to check whether the changes are reflected in the database, for example like so:
    bool Success = (cmd.ExecuteNonQuery()!= 0);
    The Success property can then be added into the associatedData dictionary, which will enable you to access it on the client-side to inform the user of the current state of the operation.

    I hope this is a good start for you. If you need further info, please let us know.

    Regards,
    Tina Stancheva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. rob mays
    rob mays avatar
    58 posts
    Member since:
    Jun 2007

    Posted 28 Sep 2010 Link to this post

    When I run your example I get uriprefix not recognised error?

  7. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 29 Sep 2010 Link to this post

    Hello rob mays,

    You need to set the UploadSaveIntoDataBaseExample.Web project as a StartUp project. Give ti a try and let me know if it works for you.

    Regards,
    Tina Stancheva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. rob mays
    rob mays avatar
    58 posts
    Member since:
    Jun 2007

    Posted 30 Sep 2010 Link to this post

    thank you that helped me further, but now have problems with inserting into the database server not found? I did change the connection string to the new location but still know further. I guess my real question is how to go about uploading an excel sheet to the webserver then loop through the records, if I am happy with the data in the excel sheet then insert the record into a database?

    I do appreciate this might not be the correct forum now so if not I thank you for the help so far it has been great.
  9. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 05 Oct 2010 Link to this post

    Hi rob mays,

    in order to implement your scenario, you can modify the SaveChunkData() event to upload the data from the uploded excel files to a database following the approach suggested here.

    I hope this information will get you started. Let us know if we can further assist you.

    Sincerely yours,
    Tina Stancheva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Steve
    Steve avatar
    4 posts
    Member since:
    Jul 2010

    Posted 02 Feb 2011 Link to this post

    Is there any way to not first save the file to a directory?
    We do not have that luxury - in the past with asp.net I could get the bytes from the upload control and save that to a database.
    With the Silverlight control is seems that I first must use base.SaveChunkData(filePath.....
    Am I missing something here?
    Thanks,
    Steve
  11. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 07 Feb 2011 Link to this post

    Hello Steve,

    Indeed the RadUpload for Silverligth is designed to upload files on the server in a specified storage. So in order to workaround this, you will need to override the RadUploadHandler ProcessStream() method to control the upload process and save the files only to the database:
    public override void ProcessStream()
    {
        this.AddReturnFileParam(RadUploadConstants.ParamNameFinalFileRequest, this.IsFinalFileRequest());
     
        if (this.IsFinalFileRequest())
        {
            HttpPostedFile fileSource = this.Request.Files[0];
            string UserID = this.GetQueryParameter("UserID");
     
            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["FilesDataBaseConnectionString"].ConnectionString;
     
            //processing the files
            byte[] array = new byte[fileSource.ContentLength];
            fileSource.InputStream.Read(array,0,fileSource.ContentLength);
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                string cmdText = "INSERT INTO FileData(FileData, FileName, UserID) VALUES(@FileData, @FileName, @UserID)  SET @Identity = SCOPE_IDENTITY()";
                SqlCommand cmd = new SqlCommand(cmdText, conn);
     
                SqlParameter identityParam = new SqlParameter("@Identity", SqlDbType.Int, 0, "FileID");
                identityParam.Direction = ParameterDirection.Output;
     
                cmd.Parameters.AddWithValue("FileData", array);
                cmd.Parameters.AddWithValue("FileName", this.GetFileName());
                cmd.Parameters.AddWithValue("UserID", UserID);
     
                cmd.Parameters.Add(identityParam);
     
                conn.Open();
     
                //checking whether the operation is successfull
                Success = (cmd.ExecuteNonQuery() != 0);
     
                FileID = (int)identityParam.Value;
     
            }
        }
        this.SendFeedback(Success, this.GetFileName(), this.GetFileName());
    }

    The code snippet above can help you get started. However, in cases when the uploaded file's size it bigger than the buffer's size, the above ProcessStream() implementation has to be customized to keep track of all file chunks sent to the UploadHandler and when the last one is received, to put the file together and save it into the database.

    Best wishes,
    Tina Stancheva
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  12. MD
    MD avatar
    55 posts
    Member since:
    Jul 2012

    Posted 10 Oct 2011 Link to this post

    How can you access the chunks to piece the file together for saving to the database or manipulation of the file.

    thanks
  13. MD
    MD avatar
    55 posts
    Member since:
    Jul 2012

    Posted 13 Oct 2011 Link to this post

    Is it possible to piece together the chunks when overriding the ProcessStream method?  I'm not interested in saving the file(s) to disk which seems to happen when overriding the SaveChunkData method for this purpose.
  14. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 13 Oct 2011 Link to this post

    Hello Md,

    The Tine's example in the previous post shows how you can override the ProcessStream method, without saving the file's chunks to the file system. Isn't that helpful or you have some other requirement?

    Best wishes,
    Alex Fidanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  15. MD
    MD avatar
    55 posts
    Member since:
    Jul 2012

    Posted 13 Oct 2011 Link to this post

    It is helpfull except for when the file size is larger than the buffer and the file is broken up into chunks.  She mentioned you would have to keep track of all the chunks and the piece them together.  What would be the perferred way to temporarily store all the chunks and then combine them?

    Thanks
  16. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 13 Oct 2011 Link to this post

    Hello Md,

    You can assume that the bytes are coming in a consecutive manner - from the start to the end. The first chunk is the start of the file and the last one is the end. Therefore, you can store them in an array or any collection by adding each chunk of bytes at the end of the array. When the final chunk arrives, the file should be complete.

    Best wishes,
    Alex Fidanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  17. Reese
    Reese avatar
    4 posts
    Member since:
    Jan 2012

    Posted 04 May 2012 Link to this post

    I've followed this conversation, but still have a question.  You said,

    "Therefore, you can store them in an array or any collection by adding each chunk of bytes at the end of the array"

    But when I try to define a variable in the upload handler, the variable gets re-initialized every time a new chunk gets saved.  How do I define a variable so that it persists across multiple chunks?
  18. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 09 May 2012 Link to this post

    Hello Reese,

    I will wrap up our discussion here as well so that the community can keep track of it as well.

    Basically in order to save large files directly in a database for example, you can override the SaveChunkData() method as demonstrated in the attached solution.

    However the approach demonstrated in the sample throws "Size not big enough" exception when uploading very large files. Therefore depending on everyone's scenario, the RadUploadHandler implementation may have to be extended - instead of uploading in the database the entire file stream, when it is too large, you can upload it in a couple of chunks.

    All the best,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  19. Barry
    Barry avatar
    4 posts
    Member since:
    Sep 2012

    Posted 20 Sep 2012 Link to this post

    Is there a clear work around for the issue of the sample project not debugging because the silverlight developer version is for 64 bit? Will not debug, says wrong version.
  20. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 25 Sep 2012 Link to this post

    Hi Barry,

    I am not sure why you can't debug the project on your side, but if you can debug a new Silverlight solution on your machine, you can just recreate the project. For that purpose, you'll have to create a new Silverlight solution and copy the code of the following files:
    • MainPage.xaml and MainPage.xaml.cs
    • SampleUploadHandler.ashx and SampleUploadHandler.ashx.cs
    • StreamFile.ashx and StreamFile.ashx.cs
     
    Kind regards,
    Tina Stancheva
    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

  21. Aravind
    Aravind avatar
    9 posts
    Member since:
    Oct 2012

    Posted 19 Nov 2012 Link to this post

    hello sir thank for your example ,here i want small changes,in UploadDirectlyIntoDataBase.zip i want to check file name is already present in database  or not ,if file name is available i want to rename manually the currently upload file in same rad upload window or use any popup window to rename before insert into database.pls reply asap thanx in advance
  22. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 22 Nov 2012 Link to this post

    Hello Aravind,

    I modified the solution to traverse the files table to check if a file with the same name already exists in it. Then I make sure to insert the uploaded file with a unique new name in case its name is already used in the table.

    The changes I implemented are mainly in the SampleUploadHandler implementation. Please note that I modified the SaveChunkData() method implementation to create a new query to the sql DataBase and find if a file name already exists. In the SampleUploadHandler, you can use the GetFileName() method to get the name of the file that is being currently uploaded. Still I created a new string property to keep the current name - the one returned by the GetFileName() method or a new unique name if the file has already been saved in the database.

    I hope this solution will get you started. Let us know if we can further assist you.

    Kind regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  23. Aravind
    Aravind avatar
    9 posts
    Member since:
    Oct 2012

    Posted 25 Nov 2012 Link to this post

    Thank u so much Tina Stancheva , actually this one is i want ,but in that the rename is work in server side,but that only i want to rename manually(i.e)user click upload button it check the database and if the name is available any popup window or navigate to new aspx page as a popup window and hold the exist file name only or it carry all currently upload file name in page load event( after that i rename)
     
    ,not like assign the random letter or number in server side,in that u change the code like if name is exist u call a GetFileName() method, instead u call a GetFileName() method,u popup window to rename.pls reply asap thanx

  24. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 28 Nov 2012 Link to this post

    Hello Aravind,

    The RadUploadHandler returns a response to the client side of the RadUpload control only after the upload session is over - successfully or unsuccessfully. In both case, the upload operation will be finished by the time you get to display a notification window or a popup to the client using Silverlight controls.

    This is why I'd recommend validating each file - using the RadUploadItem.ValidateEvent you can call your WCF service to check if the name of the file has already been entered in the database. Here, you'll also be able to provide a popup or a RadWindow prompting the user to enter a new name. As this logic is implemented in the Silverlight project, you can use any other Silverlight controls to build your UI and logic.

    I hope this information will help you.

    All the best,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  25. Otto Neff
    Otto Neff avatar
    36 posts
    Member since:
    Jul 2011

    Posted 27 Feb 2013 Link to this post

    Hi,

    just came around this problem. May some others might find this helpful:

    I solved it quite simple and straight. Placed the Upload.ashx in the ClientBin Folder. (Or wherever, adjust replacement below)

    defined HandlerName in Markup:

    <telerik:RadUpload UploadServiceUrl="Upload.ashx">

    and simple updated the value in constructor with url containing virtual folder:


    public MainPage()
        {
            InitializeComponent();
            RadUpload1.UploadServiceUrl = App.Current.Host.Source.AbsolutePath.Replace("Silverlight.xap", RadUpload1.UploadServiceUrl);
    }  


    done. cheers otto.
Back to Top
DevCraft banner