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

Two Problems: Delete Item and Validation Item

1 Answer 95 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Tarcisis
Top achievements
Rank 1
Tarcisis asked on 16 Jun 2011, 05:34 PM
Hi,

I have a telerik radWindow for upload images.
My xaml:
<telerik:RadWindow x:Class="Project.UploadCatalogPagesImages"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
           xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"    
           ResizeMode="NoResize" WindowState="Normal" WindowStartupLocation="CenterScreen" Header=""
           x:Name="radWindowUploadCatalogPagesImages">
    <Grid x:Name="LayoutRoot" Margin="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
 
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="LightGray">
            <TextBlock x:Name="txtOptions" FontSize="11" Foreground="Black" FontWeight="Bold"
                       HorizontalAlignment="Right" Margin="10" VerticalAlignment="Center"/>
 
            <telerik:RadComboBox IsEditable="False" x:Name="ComboBoxOptions" HorizontalAlignment="Left"
                                   ClearSelectionButtonVisibility="Collapsed" MinWidth="200" Margin="10" ItemsSource="{Binding PublicationTypesOptions}"
                                   SelectedItem="{Binding SelectedOption, Mode=TwoWay}" VerticalAlignment="Center" DisplayMemberPath="PubTypeDesc" SelectionChanged="ComboBoxOptions_SelectionChanged"/>
        </StackPanel>
 
        <telerik:RadUpload Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" 
                        x:Name="RadUpload" Margin="0" Width="400" Height="430"
                        Filter="Image Files (*.gif;*.jpg;*.jpeg;*.png)|*.gif;*.jpg;*.jpeg;*.png|All Files(*.*)|*.*"
                        FilterIndex="0" IsMultiselect="True"
                        IsAutomaticUpload="false"
                        OverwriteExistingFiles="True"
                        UploadServiceUrl="/FileUploadHandler.ashx"
                        IsAppendFilesEnabled="True"
                        FileUploadStarting="RadUpload1_FileUploadStarting"
                        FileUploaded="RadUpload1_FileUploaded"
                        UploadFinished="RadUpload_UploadFinished"  
                        UploadStarted="RadUpload1_UploadStarted"
                        BufferSize="50000"
                        MaxFileSize="3000000" MaxUploadSize="10000000">
            <telerik:RadUpload.ItemContainerStyle>
                <Style TargetType="telerik:RadUploadItem">
                    <Setter Property="Template">
                        <Setter.Value>
 
                            <ControlTemplate TargetType="telerik:RadUploadItem">
                                <Grid Margin="0,5">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
 
                                    <telerik:RadComboBox Grid.Column="0" IsEditable="False" x:Name="ComboBoxOptionsPage" HorizontalAlignment="Left"
                                                           ClearSelectionButtonVisibility="Collapsed" MinWidth="50" Margin="10" ItemsSource="{Binding CataloguePages}"
                                                           SelectedItem="{Binding SelectedOption, Mode=TwoWay}" EmptyText="Seleccione" VerticalAlignment="Center" DisplayMemberPath="Description"/>
                                     
                                    <Border Grid.Column="1">
                                        <Grid>
                                            <telerik:RadProgressBar Height="25" MinHeight="20"
                                                x:Name="FileProgressBar" Minimum="0" Maximum="100"></telerik:RadProgressBar>
                                            <TextBlock Text="{TemplateBinding FileName}"
                                            HorizontalAlignment="Left" VerticalAlignment="Center"
                                            Margin="10,0,0,0" TextWrapping="NoWrap" />
                                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"
                                            VerticalAlignment="Center">
                                                <TextBlock Text="{TemplateBinding FileSize}"
                                                Margin="0,0,10,0" TextWrapping="NoWrap"
                                                VerticalAlignment="Center" />
                                                <Grid VerticalAlignment="Center" ShowGridLines="True"
                                                Height="25">
                                                    <Path VerticalAlignment="Center" x:Name="IconDelete"
                                                    Margin="0,-4,10,0" Cursor="Hand" Stretch="Fill"
                                                    Fill="#FF000000"
                                                    Data="M5.0000001,0 L7,0 7,5 12,5 12,7 7,7 7,12 5.0000001,12 5.0000001,7 0,7 0,5 5.0000001,5 5.0000001,0 z"
                                                    Width="12" Height="12">
                                                        <Path.RenderTransform>
                                                            <TransformGroup>
                                                                <RotateTransform Angle="45" />
                                                            </TransformGroup>
                                                        </Path.RenderTransform>
                                                    </Path>
                                                    <Path VerticalAlignment="Center" x:Name="IconDone"
                                                    Margin="0,0,10,0" Stretch="Fill"
                                                    Visibility="Collapsed" Fill="#FF000000"
                                                    Data="M719.90131,266.74252 L728,276.64667 L743.13574,254.96999 L727.96881,271.52853"
                                                    Width="12" Height="12" />
                                                    <Grid VerticalAlignment="Center" x:Name="IconError"
                                                    Margin="0,0,10,0" Visibility="Collapsed"
                                                    Width="14.6" Height="18">
                                                        <Path Stretch="Fill" Stroke="#FFFFFFFF"
                                                        Margin="0,1.786,0,3.288"
                                                        Data="M577.89149,269.68195 L584.80031,257.78582 591.50111,269.64775 z">
                                                            <Path.Fill>
                                                                <LinearGradientBrush EndPoint="0.5,0"
                                                                StartPoint="0.5,1">
                                                                    <GradientStop Color="#FFFFC600"
                                                                    Offset="0" />
                                                                    <GradientStop Color="#FFFDFF00"
                                                                    Offset="1" />
                                                                </LinearGradientBrush>
                                                            </Path.Fill>
                                                        </Path>
                                                        <TextBlock Margin="6,4,6,4" Width="Auto"
                                                        Height="Auto" FontSize="8" FontWeight="Bold"
                                                        Text="!" TextWrapping="Wrap" />
                                                    </Grid>
                                                </Grid>
                                            </StackPanel>
                                        </Grid>
                                    </Border>
 
 
                                </Grid>
                            </ControlTemplate>
 
                        </Setter.Value>
                    </Setter>
 
 
                </Style>
            </telerik:RadUpload.ItemContainerStyle>
 
        </telerik:RadUpload>
 
    </Grid>
</telerik:RadWindow>

First Problem: the delete icon doesn´t work.

Second Problem:

I want to make validations for each item before upload starting.
So in my .cs i have:
private void RadUpload1_UploadStarted(object sender, Telerik.Windows.Controls.UploadStartedEventArgs e)
{
    cataloguePagesForValidation = new Dictionary<string, string>();
    cataloguePagesForImages = new Dictionary<string, string>();
    try
    {
        foreach (RadUploadItem item in RadUpload.Items)
        {
            RadComboBox descriptionTextBox = item.FindChildByType<RadComboBox>();
            cataloguePagesForValidation.Add(((Pages)(descriptionTextBox.SelectedValue)).Id, item.FileName);
            cataloguePagesForImages.Add(item.FileName, ((Pages)(descriptionTextBox.SelectedValue)).Id);
        }
    }
    catch
    {
            this.RadUpload.CancelUpload();
    }
 
 
}

   

I have a RadComboBox for each item that i selected. For each item i must to choose a type.
So, in method RadUpload1_UploadStarted, if the radcombobox is empty or something else....i want to cancel the uploading files without clear the elements.The problem is that "this.RadUpload.CancelUpload" clear all the items.

Thanks

1 Answer, 1 is accepted

Sort by
0
Alex Fidanov
Telerik team
answered on 21 Jun 2011, 03:35 PM
Hi Tarcisis,

Thank you for providing the xaml code snippet. This seems to be a modified style and template of the old RadUploadItem's style. We made a refactoring on the UI related code of the Upload and UploadItem. We added VSM and commands, which is the case with the delete command. I would recommend going through the new UploadItem template (in Blend) and updating your current style.

Regarding the validation, I would not recommend the UploadStarted event, as the upload session has already started uploading. The UploadItem has a Validate event, which will be called when the item is ready to be uploaded, so you can perform your validation there.

Cancelling the upload will clear the current session and all of the selected files. What you can do is to store the FileInfo objects of the current items in the Upload control and re-add them back to the Upload control. You can see how to add files in procedural code in the Upload in our help here.

All the best,
Alex Fidanov
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
Tags
Upload
Asked by
Tarcisis
Top achievements
Rank 1
Answers by
Alex Fidanov
Telerik team
Share this question
or