This is a migrated thread and some comments may be shown as answers.
Tilde in UploadServiceUrl ignores virtual dir
23 Answers 393 Views
This is a migrated thread and some comments may be shown as answers.
Anders
Top achievements
Rank 1
Anders asked on 25 Jun 2010, 04:39 PM
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

23 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 01 Jul 2010, 03:08 PM
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
0
rob mays
Top achievements
Rank 1
answered on 13 Sep 2010, 02:16 PM
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?
0
Tina Stancheva
Telerik team
answered on 16 Sep 2010, 03:45 PM
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
0
rob mays
Top achievements
Rank 1
answered on 28 Sep 2010, 01:58 PM

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

0
Tina Stancheva
Telerik team
answered on 29 Sep 2010, 08:53 AM
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
0
rob mays
Top achievements
Rank 1
answered on 30 Sep 2010, 10:10 AM
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.
0
Tina Stancheva
Telerik team
answered on 05 Oct 2010, 09:43 PM
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
0
Steve
Top achievements
Rank 1
answered on 02 Feb 2011, 10:23 PM
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
0
Tina Stancheva
Telerik team
answered on 07 Feb 2011, 05:39 PM
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>>
0
MD
Top achievements
Rank 1
answered on 10 Oct 2011, 10:31 PM
How can you access the chunks to piece the file together for saving to the database or manipulation of the file.

thanks
0
MD
Top achievements
Rank 1
answered on 13 Oct 2011, 03:47 PM
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.
0
Alex Fidanov
Telerik team
answered on 13 Oct 2011, 04:19 PM
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 >>

0
MD
Top achievements
Rank 1
answered on 13 Oct 2011, 04:42 PM
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
0
Alex Fidanov
Telerik team
answered on 13 Oct 2011, 04:51 PM
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 >>

0
Reese
Top achievements
Rank 1
answered on 04 May 2012, 01:45 PM
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?
0
Tina Stancheva
Telerik team
answered on 09 May 2012, 03:29 PM
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 >>

0
Barry
Top achievements
Rank 1
answered on 20 Sep 2012, 06:06 PM
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.
0
Tina Stancheva
Telerik team
answered on 25 Sep 2012, 12:50 PM
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.

0
Aravind
Top achievements
Rank 1
answered on 20 Nov 2012, 05:40 AM
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
0
Tina Stancheva
Telerik team
answered on 22 Nov 2012, 03:17 PM
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.

0
Aravind
Top achievements
Rank 1
answered on 26 Nov 2012, 04:37 AM
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

0
Tina Stancheva
Telerik team
answered on 28 Nov 2012, 02:09 PM
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.

0
Otto Neff
Top achievements
Rank 2
answered on 27 Feb 2013, 10:16 AM
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.
Asked by
Anders
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
rob mays
Top achievements
Rank 1
Steve
Top achievements
Rank 1
MD
Top achievements
Rank 1
Alex Fidanov
Telerik team
Reese
Top achievements
Rank 1
Barry
Top achievements
Rank 1
Aravind
Top achievements
Rank 1
Otto Neff
Top achievements
Rank 2
Share this question
or