This is a migrated thread and some comments may be shown as answers.

Upload control only works in debug mode in VS2010

9 Answers 126 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Lance
Top achievements
Rank 1
Lance asked on 07 Apr 2011, 05:19 AM
Hi,

I am using the RadUpload control in my Silverlight 4 application and it works correctly if I launch the application via debug in Visual Studio 2010.  If I go straight to this application via the browser or if I start it in Visual Studio with "Start Without Debugging", it fails with the error: "Handler not found or execution of the handler failed!  The remote server returned an error: NotFound.  Check RadUpload's BufferSize property remarks.". 

This error occurs after selecting the file to upload from the FileDialog and is captured in the e.ErrorMessage of the FileUploadFailed event.  It worked okay before.  I am currently using 2011_1_0328 version of the Telerik controls.

If I navigate directly to the handler in the browser I get "{"JSONData":[{"Key":"RadUAG_message","Value":"Empty file name"},{"Key":"RadUAG_success","Value":false}]}".

Please help.

9 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 12 Apr 2011, 01:40 PM
Hello Tim English,

We cannot be sure what is the cause for your issue since we can't reproduce it on our side. However, since navigating to the handler gives you this output:
"{"JSONData":[{"Key":"RadUAG_message","Value":"Empty file name"},{"Key":"RadUAG_success","Value":false}]}".
then the handler can be reached through that path. Therefore the issue might be caused either by an error in the path set in the RadUpload.UploadServiceUrl (do you define an absolute or a relative url, can you try setting the url you use to navigate to it in the browser?) or by some settings in your IIS.

Where do you deploy your application and where do you try to reach it? Basically the VisualStudio uses an ASP.NET server to deploy the applications in debug mode and this is why the application runs correctly in debug mode and doesn't otherwise. So you may need to adjust the setting in your IIS (if your application is deployed in IIS).

Kind 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
Lance
Top achievements
Rank 1
answered on 14 Apr 2011, 06:51 AM
Hi Tina,

I am using a relative path and using iis.  I ran the application with Firebug and in debug mode the path to the handler was correct (see correctpathtoraduploadhandlerindebug.gif).  When I ran it out of debug, the path to the RadUploadHandler was incorrect (see correctpathtoraduploadhandleroutofdebug.gif).  Please ignore the other two files uploaded; I made a mistake and wasn't able to delete them.

Below is some of my code which may help.  Please help me with this it is getting urgent.

My RadHandler cs code:
using Telerik.Windows;
using System.IO;
  
namespace _4Cast.Web
{
   /// <summary>
   /// Summary description for RadSilverlightUploadHandler
   /// </summary>
   public class RadSilverlightUploadHandler : RadUploadHandler
   {
  
      public RadSilverlightUploadHandler()
      {
           
      }
  
      public override string GetTargetFolder()
      {
         string targetFolder = base.GetTargetFolder();
         string userId = GetQueryParameter("UserId");
  
         if (!string.IsNullOrEmpty(userId)  && !targetFolder.EndsWith(userId))
         {
            targetFolder += Path.DirectorySeparatorChar + userId;
         }
  
         //Modify targetFolder
         return targetFolder;
      }
  
      private bool PrepareStorageFolder()
      {
         string folderPath = GetTargetFolder();
  
         if (!Directory.Exists(folderPath))
         {
            Directory.CreateDirectory(folderPath);
         }
  
         return Directory.Exists(folderPath);
      }
  
  
      public override bool SaveChunkData(string filePath, long position, byte[] buffer, int contentLength, out int savedBytes)
      {
         PrepareStorageFolder();
  
         return base.SaveChunkData(filePath, position, buffer, contentLength, out savedBytes);
      }
}

My custom upload control xaml:
<UserControl x:Class="_4Cast.UploadFilesControl"
    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
    xmlns:this="clr-namespace:_4Cast"
    xmlns:theming="clr-namespace:System.Windows.Controls.Theming;assembly=System.Windows.Controls.Theming.Toolkit"
    >
    <Grid x:Name="LayoutRoot" VerticalAlignment="Top" HorizontalAlignment="Left">
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition Height="25"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
  
        <StackPanel Grid.Row="0" Grid.Column="0" x:Name="spFiles" Orientation="Vertical" Visibility="Visible">
            <Border x:Name="brdHeader" Background="{StaticResource BlackHeader_Background}" Height="30" Width="{Binding Path=Width, ElementName=LayoutRoot}" >
                <TextBlock x:Name="txtHeader" Foreground="White" Height="30" Width="{Binding Path=Width, ElementName=LayoutRoot}" Margin="12,0,0,-15">Uploaded Files:</TextBlock>
            </Border>
            <this:MyListBox x:Name="lstFiles" KeyDown="lstFiles_KeyDown" SelectionMode="Multiple" VerticalAlignment="Top" HorizontalAlignment="Left" Width="{Binding Path=Width, ElementName=LayoutRoot}" />
            <StackPanel x:Name="spProgress" VerticalAlignment="Center" Visibility="Collapsed">
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                    <TextBlock HorizontalAlignment="Center" x:Name="loadingText" Text="Loading... " FontSize="20"  />
                    <TextBlock HorizontalAlignment="Center" x:Name="loadingPercentage" Text="" FontSize="20"  />
                </StackPanel>
                <telerik:RadProgressBar x:Name="pb" Width="260" Height="30" Minimum="0" Maximum="1000" Margin="0,0,0,30" />
            </StackPanel>
        </StackPanel>
  
  
        <Button Grid.Row="1" Grid.Column="0" x:Name="btnUpLoad" Click="btnUpLoad_Click" Height="25"/>
    </Grid>
</UserControl>

My custom upload control cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Windows.Browser;
using System.ServiceModel;
using System.Windows.Threading;
using System.Diagnostics;
using System.ServiceModel.Channels;
  
namespace _4Cast
{
   public partial class UploadFilesControl : UserControl
   {
      private string _UploadType = string.Empty;
      private string _UploadServiceUrl = "../RadSilverlightUploadHandler.ashx";
      private string _FileFilter = "All Files (*.*)|*.*";
      private int _MaxFileSizeInKilobytes = 3072;
      private int _MaxUploadSizeInKilobytes = 10240;
      private int _ParentId = 0;
      private string strSelectedFileName = string.Empty;
      private Brush _BackColour;
      private OpenFileDialog dialog = new OpenFileDialog();
      private string _UploadDestination = "UserUploads/";
      private string _UploadButtonText = "Upload";
      private static Telerik.Windows.Controls.RadUpload ruAttachments = new Telerik.Windows.Controls.RadUpload();
      private double UserControlHeight = 190;
      private double UserControlWidth = 400;
  
      private List<string> FilesMarkedForDeletion = new List<string>();
  
      public UploadFilesControl()
      {
         InitializeComponent();
  
         Loaded += UploadFilesControl_Loaded;
         Unloaded += UploadFilesControl_Unloaded;
      }
  
      void UploadFilesControl_Loaded(object sender, RoutedEventArgs e)
      {
         try
         {
            ruAttachments.UploadServiceUrl = UploadServiceUrl;
            ruAttachments.MaxFileSize = MaxFileSizeInKilobytes * 1024;
            ruAttachments.MaxUploadSize = MaxFileSizeInKilobytes * 1024;
            ruAttachments.Filter = FileFilter;
            ruAttachments.TargetFolder = UploadDestination;
            ruAttachments.IsAutomaticUpload = true;
            ruAttachments.OverwriteExistingFiles = true;
            ruAttachments.IsPauseEnabled = false;
            ruAttachments.UploadServiceUrl = "../RadSilverlightUploadHandler.ashx";
            ruAttachments.FileUploadStarting += ruAttachments_FileUploadStarting;
            ruAttachments.UploadStarted += ruAttachments_UploadStarted;
            ruAttachments.UploadFinished += ruAttachments_UploadFinished;
            ruAttachments.ProgressChanged += ruAttachments_ProgressChanged;
            ruAttachments.FileUploadFailed += ruAttachments_FileUploadFailed;
            ruAttachments.FileCountExceeded += ruAttachments_FileCountExceeded;
            ruAttachments.FileTooLarge += ruAttachments_FileTooLarge;
  
  
            btnUpLoad.Content = UploadButtonText;
  
            if (!double.IsNaN(Height) || Height > 0)
            {
               UserControlHeight = Height;
            }
  
            if (!double.IsNaN(Width) || Width > 0)
            {
               UserControlWidth = Width;
            }
  
            LayoutRoot.Height = UserControlHeight;
            LayoutRoot.Width = UserControlWidth;
  
            lstFiles.Height = LayoutRoot.Height - (brdHeader.Height + btnUpLoad.Height);
         }
         catch
         {
         }
      }
  
      void UploadFilesControl_Unloaded(object sender, RoutedEventArgs e)
      {
         try
         {
            ruAttachments.FileUploadStarting -= ruAttachments_FileUploadStarting;
            ruAttachments.UploadStarted -= ruAttachments_UploadStarted;
            ruAttachments.UploadFinished -= ruAttachments_UploadFinished;
            ruAttachments.ProgressChanged -= ruAttachments_ProgressChanged;
            ruAttachments.FileUploadFailed -= ruAttachments_FileUploadFailed;
            ruAttachments.FileCountExceeded -= ruAttachments_FileCountExceeded;
            ruAttachments.FileTooLarge -= ruAttachments_FileTooLarge;
         }
         catch
         {
         }
      }
  
      public bool IsDirty
      {
         get
         {
            return lstFiles.Items.Count > 0;
         }
      }
  
      public List<string> UploadedFiles
      {
         get
         {
            List<string> uf = new List<string>();
  
            for (int i = 0; i < lstFiles.Items.Count; i++)
            {
               uf.Add(lstFiles.Items[i].ToString());
            }
  
            return uf;
         }
      }
  
      void ruAttachments_FileUploadStarting(object sender, Telerik.Windows.Controls.FileUploadStartingEventArgs e)
      {
         e.FileParameters.Add("UserId", App.WcfPushClient.UserId);
      }
  
      private void ruAttachments_UploadStarted(object sender, Telerik.Windows.Controls.UploadStartedEventArgs e)
      {
         lstFiles.Visibility = Visibility.Collapsed;
         spProgress.Visibility = Visibility.Visible;
      }
  
      void ruAttachments_ProgressChanged(object sender, RoutedEventArgs e)
      {
         try
         {
            pb.Value += ruAttachments.CurrentSession.CurrentFileProgress;
            int value = Math.Max(0, Math.Min(100, Convert.ToInt32((pb.Value / (pb.Maximum - pb.Minimum)) * 100)));
            loadingPercentage.Text = value.ToString() + " %";
  
            if (Convert.ToInt32((pb.Value / (pb.Maximum - pb.Minimum) * 100)) == 100)
            {
               loadingText.Text = "Loaded    ";
            }
         }
         catch
         {
         }
      }
  
      void ruAttachments_FileUploadFailed(object sender, Telerik.Windows.Controls.FileUploadFailedEventArgs e)
      {
         MessageBox.Show(e.ErrorMessage, "Upload Error", MessageBoxButton.OK);
      }
  
      void ruAttachments_FileTooLarge(object sender, Telerik.Windows.Controls.FileEventArgs e)
      {
         MessageBox.Show("Unable to upload file (" + e.SelectedFile.Name + ") because at " + e.SelectedFile.Size.ToString() + "bytes, it exceeds the maximum upload size of " + ruAttachments.MaxFileSize.ToString() + "bytes.", "Upload Error", MessageBoxButton.OK);
      }
  
      void ruAttachments_FileCountExceeded(object sender, RoutedEventArgs e)
      {
         MessageBox.Show("Unable to complete uploading all files because the maximum number of files that can be uploaded (" + ruAttachments.MaxFileCount + ") has been exceeded.", "Upload Error", MessageBoxButton.OK);
      }
  
      private void ruAttachments_UploadFinished(object sender, RoutedEventArgs e)
      {
         lstFiles.Visibility = Visibility.Visible;
         spProgress.Visibility = Visibility.Collapsed;
  
         pb.Value = pb.Minimum;
         loadingText.Text = "Loading... ";
  
         FillListBoxWithUploadFiles();
      }
  
      private void btnUpLoad_Click(object sender, RoutedEventArgs e)
      {
         ruAttachments.ShowFileDialog();
      }
  
      private void lstFiles_KeyDown(object sender, KeyEventArgs e)
      {
         try
         {
            switch (e.Key)
            {
               case Key.Delete:
                  if (lstFiles.SelectedItems != null && lstFiles.SelectedItems.Count > 0)
                  {
                     for (int i = 0; i < lstFiles.SelectedItems.Count; i++)
                     {
                        for (int r = 0; r < ruAttachments.Items.Count; r++)
                        {
                           Telerik.Windows.Controls.RadUploadItem rui = ruAttachments.Items[r] as Telerik.Windows.Controls.RadUploadItem;
  
                           if (rui != null)
                           {
                              if (rui.FileName == lstFiles.SelectedItems[i].ToString())
                              {
                                 FilesMarkedForDeletion.Add(lstFiles.SelectedItems[i].ToString());
                                 ruAttachments.Items.Remove(rui);
                              }
                           }
                        }
                     }
  
                     lstFiles.Items.Clear();
                     FillListBoxWithUploadFiles();
                     DeleteFilesMarkedForDeletion();
                  }
  
                  break;
            }
         }
         catch
         {
         }
      }
  
      public void ClearUploadedFiles()
      {
         UploadedFiles.Clear();
         lstFiles.Items.Clear();
         spProgress.Visibility = Visibility.Collapsed;
      }
  
      private void FillListBoxWithUploadFiles()
      {
         try
         {
            for (int i = 0; i < ruAttachments.Items.Count; i++)
            {
               Telerik.Windows.Controls.RadUploadItem rui = ruAttachments.Items[i] as Telerik.Windows.Controls.RadUploadItem;
  
               if (rui != null && !lstFiles.Items.Contains(rui.FileName))
               {
                  lstFiles.Items.Add(rui.FileName);
               }
            }
         }
         catch
         {
         }
      }
  
      public Brush BackColour
      {
         get
         {
            return _BackColour;
         }
         set
         {
            _BackColour = value;
            LayoutRoot.Background = _BackColour;
         }
      }
  
      public string UploadDestination
      {
         get
         {
            if (UploadType.Length > 0 && !_UploadDestination.EndsWith(UploadType))
            {
               _UploadDestination += UploadType;
            }
  
            return _UploadDestination;
         }
      }
  
      public string UploadType
      {
         get
         {
            //Ensure contains only 1 trailing '/'
            _UploadType = _UploadType.TrimEnd(System.IO.Path.AltDirectorySeparatorChar) + System.IO.Path.AltDirectorySeparatorChar;
  
            return _UploadType;
         }
         set
         {
            _UploadType = value;
         }
      }
  
      public string UploadServiceUrl
      {
         get
         {
            return _UploadServiceUrl;
         }
         set
         {
            _UploadServiceUrl = value;
         }
      }
  
      public string UploadButtonText
      {
         get
         {
            return _UploadButtonText;
         }
         set
         {
            _UploadButtonText = value;
         }
      }
  
      public string FileFilter
      {
         get
         {
            return _FileFilter;
         }
         set
         {
            _FileFilter = value;
            dialog.Filter = _FileFilter;
         }
      }
  
      public int ParentId
      {
         get
         {
            return _ParentId;
         }
         set
         {
            _ParentId = value;
         }
      }
  
      public int MaxFileSizeInKilobytes
      {
         get
         {
            return _MaxFileSizeInKilobytes;
         }
         set
         {
            _MaxFileSizeInKilobytes = value;
         }
      }
  
      public int MaxUploadSizeInKilobytes
      {
         get
         {
            return _MaxUploadSizeInKilobytes;
         }
         set
         {
            _MaxUploadSizeInKilobytes = value;
         }
      }
  
  
  
  
      public void DeleteFilesMarkedForDeletion()
      {
         try
         {
            FilesMarkedForDeletion.ForEach(f =>
            {
               //Don't delete current choice.
               if (f.Length > 0)
               {
                  try
                  {
                     App.FileManagementClient.DeleteUploadedFileAsync(UploadDestination.Replace(System.IO.Path.AltDirectorySeparatorChar, System.IO.Path.DirectorySeparatorChar), f, App.WcfPushClient.UserId);
                  }
                  catch (CommunicationException commEx)
                  {
                     FaultException faultEx = commEx as FaultException;
  
                     if (faultEx == null)
                     {
                        App.FileManagementClient.DeleteUploadedFileAsync(UploadDestination.Replace(System.IO.Path.AltDirectorySeparatorChar, System.IO.Path.DirectorySeparatorChar), f, App.WcfPushClient.UserId);
                     }
                  }
               }
            });
  
            FilesMarkedForDeletion.Clear();
         }
         catch
         {
         }
      }
}
}

0
Tim
Top achievements
Rank 1
answered on 15 Apr 2011, 09:32 PM
I am having this issue as well.  I did a release build and deployed to our production server and I was getting the "Check RadUpload's Buffersize property remarks" error.  I switched to a debug build and deployed and it went away.
0
Nick Wood
Top achievements
Rank 1
answered on 19 Apr 2011, 10:44 AM
Hi All

Any resolution for this issue as I am having the exact same problem?

Nick
0
Tina Stancheva
Telerik team
answered on 19 Apr 2011, 02:13 PM
Hello guys,

Unfortunately we cannot reproduce this issue on our side. I created a project based on the code Tim English sent and I deployed it in IIS - you can see this screencast that illustrates how the project is deployed, and the application works as expected. I attached the sample project to this thread as well. Am I missing something?

At this point I am at a loss as to why you are seeing the exception. However, since your code works as expected on our side, I believe that the cause for the issue is in your environment settings. Therefore any additional info that you can give us about that might help.

Also, you can have a look at this Troubleshooting RadUpload KB article, some of the hints there might help you.

Best wishes,
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
Edward Pauley
Top achievements
Rank 1
answered on 06 May 2011, 11:16 PM
Hi 
i also get the same problem. 
Check your sample project to compare with mine and the trouble shooting link but don't see any difference

Does anyone manage to resolve this problem? plz help me

or can telerik make a video from beginning to end at how you create the RadUpload handler, setting IIS from start to end? i look at your provided video and that one doesn't really helpful at all because it doesn't show any setting in IIS

thanks
0
Tim
Top achievements
Rank 1
answered on 07 May 2011, 12:19 AM
@Edward

Thanks for the reminder.  I was part of this thread earlier and didn't have a solution until recently.  This might work for you:

For about 6 months these 2 lines of code worked fine to set the path to my upload service.  Note the 2 periods for a relative path

RadUpload radUpload = new RadUpload();
radUpload.UploadServiceUrl = "../FileUploadHandler.ashx";

I then changed it the code to explictly define the path and I could once again get my radupload to work in release or debug.

RadUpload radUpload = new RadUpload();
string sBaseUrl = Application.Current.Host.Source.ToString().ToLower();
int iIndexOfClientBin = sBaseUrl.IndexOf("/clientbin");
sBaseUrl = sBaseUrl.Substring(0, iIndexOfClientBin);
radUpload.UploadServiceUrl = sBaseUrl + "/FileUploadHandler.ashx";

BTW - Is there a more elegant way to get the Base URL?

-Tim
0
Tina Stancheva
Telerik team
answered on 11 May 2011, 06:22 PM
Hello guys,

We did our best to reproduce the problem on our side, but to no avail. This is why we are not sure what might be causing this issue. If you have any thought on how we might be able to reproduce it, that would be much appreciated.

In the meantime,
@Tim
The RadUpload internally uses similar to your BaseUrl logic to construct the url of the UploadHandler and this is why its strange that the radUpload.UploadServiceUrl = "../FileUploadHandler.ashx"; definition doesn't work. However, we are definitely glad to hear that you found an approach that works for you.

@ Edward
Can you give Tim's approach a try and let us know if it works for you? Thanks in advance.

Kind 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
Edward Pauley
Top achievements
Rank 1
answered on 11 May 2011, 07:12 PM
Hi

Tim's approach really works for me.

the approach "../FileHandler.ashx" doesn't work

thanks
Tags
Upload
Asked by
Lance
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Lance
Top achievements
Rank 1
Tim
Top achievements
Rank 1
Nick Wood
Top achievements
Rank 1
Edward Pauley
Top achievements
Rank 1
Share this question
or