前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >telerik upload 在silv

telerik upload 在silv

作者头像
py3study
发布于 2020-01-14 07:58:42
发布于 2020-01-14 07:58:42
4440
举报
文章被收录于专栏:python3python3

打开SL工程添加引用Telerik.Windows.Controls.dll and Telerik.Windows.Controls.Input.dll. 以及在Page.xaml中添加RadUpload控件 <telerikInput:RadUpload     x:Name="radUpload"     Filter="All Files(*.*)|*.*"     FilterIndex="3"     IsAutomaticUpload="False"     OverwriteExistingFiles="True"     UploadServiceUrl="../RadUploadHandler.ashx"     TargetFolder="MyStorageFolder"     FileUploaded="radUpload_FileUploaded"     >   </telerikInput:RadUpload>  

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 Telerik.Windows.Controls; using Telerik.Windows; using System.Windows.Media.Imaging;

namespace TelerikDemo {     public partial class MainPage : UserControl     {         public MainPage()         {             InitializeComponent();         }

        private void radUpload_FileUploaded(object sender, FileUploadedEventArgs e)         {             RadUploadSelectedFile uploadedFile = e.SelectedFile;             // CustomData is a Dictionary property that stores the new file name in value of a key.             // This key is set in the RadUploadHandler.ashx.cs             string newFileName = e.HandlerData.CustomData["NewFileName"].ToString();

            if (this.radUpload.CurrentSession.FileNameUploadItem.ContainsKey(uploadedFile.Name))             {                 RadUploadItem item = this.radUpload.CurrentSession.FileNameUploadItem[uploadedFile.Name];                 if (item != null)                 {                     // Retrieve the TextBlock that will hold new file name                     FrameworkElement element = GetCustomTagControl(item, "NewFileName");                     if (element != null)                     {                         TextBlock textBlock = element as TextBlock;                         if (textBlock != null)                         {                             textBlock.Text = newFileName;                             textBlock.Visibility = Visibility.Visible;                         }                     }                 }             }         }

        private static FrameworkElement GetCustomTagControl(DependencyObject control, string name)         {             for (int i = 0; i < VisualTreeHelper.GetChildrenCount(control); i++)             {                 DependencyObject child = VisualTreeHelper.GetChild(control, i);                 FrameworkElement element = child as FrameworkElement;

                if (element != null)                 {                     if (0 == string.Compare(element.Name, name, StringComparison.InvariantCultureIgnoreCase))                     {                         return element;                     }                 }                 element = GetCustomTagControl(child, name);                 if (element != null)                 {                     return element;                 }             }             return null;         }     } } 打开RadUploadDemo.Web并且添加引用Telerik.Windows.RadUploadHandler.dll.  在这之后,右击RadUploadDemo.Web选择添加新item,添加一个名为RadUploadHandler.ashx的 Generic Handler,也添加一个新文件夹名为MyStorageFolder

打开RadUploadHandler.ashx文件,你的handler需继承Telerik.Windows.RadUploadHandler并且重写一部分重要的函数

<%@ WebHandler Language="C#" Class="RadUploadHandler" %>

using System; using System.Web; using System.Collections.Generic;

public class RadUploadHandler : Telerik.Windows.RadUploadHandler {

    private string newFileName = string.Empty;

    //public override void ProcessStream()     //{     //    if (this.IsNewFileRequest())     //    {     //        this.ResultChunkTag = string.Format("[{0;yyyymmdd.hhmmss}]",DateTime.Now);     //    }     //    else if (this.FormChunkTag != null)     //    {     //        this.ResultChunkTag = this.FormChunkTag;     //    }     //    base.ProcessStream();     //}

    public override Dictionary<string, object> GetAssociatedData()     {         Dictionary<string, object> dict = base.GetAssociatedData();         if (!string.IsNullOrEmpty(newFileName))         {             dict.Add("NewFileName", this.newFileName);         }         return dict;     }

    public override string GetFilePath(string fileName)     {         fileName = base.GetFilePath(this.GetFileName(fileName));         return fileName;     }

    private string GetFileName(string fileName)     {         if (this.IsNewFileRequest())         {             this.ResultChunkTag = string.Format(" [{0:yyyymmdd_hhmmss}]", DateTime.Now);         }

        else if (this.FormChunkTag != null)         {             this.ResultChunkTag = this.FormChunkTag;         }

        if (this.ResultChunkTag != null)         {             int i = fileName.LastIndexOf('.');             if (i >= 0)             {                 fileName = fileName.Insert(i, this.ResultChunkTag);             }         }         return this.newFileName = fileName;     } }

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/07/04 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
dotnet UNO 如何在调试下输出界面层级结构
实现方法非常简单,和 WPF 或 UWP 等的方法是一样的,那就是通过可视化树遍历的方式,如以下代码
林德熙
2023/11/28
1220
C#-ListBox多选绑定
ListBox有一个依赖属性SelectedItems,但是这个属性是只读的,所以无法适用绑定,来自动获取多选项,如何通过绑定获取多选项,我们可以使用附加属性来实现。
kdyonly
2024/12/19
1070
Notes on Migrating from WPF to UNO under UOS
This article documents my experience in migrating a small WPF application to the UNO framework for support on the UOS(统信).
林德熙
2023/11/28
2010
Notes on Migrating from WPF to UNO under UOS
Silverlight Telerik控件学习:RadTransitionControl
如果展示类似这种比较cool的图片轮换效果,用RadTransitionControl控件就对了,它提供的过渡效果非常cool! 原理并不复杂,可参见以前写的 Silverlight之ListBox/Style学习笔记--ListBox版的图片轮换广告. xaml部分: <UserControl xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" x:Class="Telerik.Sample.Transition"
菩提树下的杨过
2018/01/23
8120
Silverlight Telerik控件学习:RadTransitionControl
实现一个 WPF 版本的 ConnectedAnimation
2017-12-25 11:44
walterlv
2018/09/18
6630
实现一个 WPF 版本的 ConnectedAnimation
自学WP7第一个例子:时钟
自学WP7做的第一个程序:时钟 做的很山寨,没用素材 用TextBlock做的表盘和指针,放在一个Canvas上 RotateTransform类来控制偏移角度 MainPage.xaml <phone:PhoneApplicationPage x:Class="Clock.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.micro
Porschev
2018/01/16
4610
自学WP7第一个例子:时钟
silverlight:telerik RadControls中RadGridView的一个Bug及解决办法
当RadGridView中嵌套RadComboBox,且RadGridView的高度不够出现滚动条时,上下拉动滚动条后,RadComboBox中的选中值将丢失! 如下图: 滚动条未拖动前 滚动条上下拖
菩提树下的杨过
2018/01/24
7780
silverlight:telerik RadControls中RadGridView的一个Bug及解决办法
Silverlight Telerik控件学习:带CheckBox复选框的树形TreeView控件
在web开发中,带checkbox的tree是一个很有用的东东,比如权限选择、分类管理,如果不用sl,单纯用js+css实现是很复杂的,有了SL之后,就变得很轻松了 解决方案一: 利用Silvelright ToolKit(微软的开源项目),项目地址http://silverlight.codeplex.com/ 在线演示地址:http://silverlight.net/content/samples/sl4/toolkitcontrolsamples/run/default.html 解决方案二
菩提树下的杨过
2018/01/23
2.1K0
Silverlight Telerik控件学习:带CheckBox复选框的树形TreeView控件
WPF桌面端开发2-ItemsControl和ListBox获取点击行的索引
ItemsControl和ListBox都可以用做列表,既然是列表,那么我们怎样获取列表点击的项呢。
码客说
2020/05/09
2.9K0
VisualTreeHelper
Silverlight中只有可视化树,没有WPF中的逻辑树,这一点可从SL的sdk文档中得到印证: 可视化树概念也存在于 WPF 中,它与 Silverlight 的可视化树概念类似。然而,一个显著的差异是 WPF 还提供一个附加的筛选器或对象树(称为"逻辑树")的概念。逻辑树概念与某些属性系统行为相关。Silverlight 不通过帮助器类来公开此逻辑树。Silverlight 中的确存在某些(但并非所有)相关的属性行为,但由于没有用于访问这些行为的帮助器 API,因此,逻辑树概念在 Silverligh
菩提树下的杨过
2018/01/23
8300
VisualTreeHelper
关于radcontrols控件之Radupload「建议收藏」
Namespace: Telerik.Windows.Controls Assembly: Telerik.Windows.Controls.Input (in Telerik.Windows.Controls.Input.dll)
全栈程序员站长
2022/09/15
3880
关于radcontrols控件之Radupload「建议收藏」
简单在 WinUI 仿造 WPF 的 ColumnDefinition SharedSizeGroup 共享列宽功能
本文将告诉大家如何在 WinUI 3 或 UNO 里面,仿造 WPF 的 ColumnDefinition SharedSizeGroup 共享列宽功能
林德熙
2024/08/11
960
简单在 WinUI 仿造 WPF 的 ColumnDefinition SharedSizeGroup 共享列宽功能
Silverlight:利用异步加载Xap实现自定义loading效果
关键点: 1.利用WebClient的DownloadProgressChanged事件更新下载进度 2.下载完成后,分析Xap包的程序集Assembly信息 3.利用Assembly反射还原对象并加载到当前页中。 好处: 1.可以先定义一个简单的加载动画,吸引用户注意,避免长时间的无聊等待,改善用户体验。 2.实现按需加载,避免一次性下载过多内容。 3.在一定程度上,增加了破解难度,有助于代码保密。 Xaml : <UserControl x:Class="LoadXap.MainPage"     xm
菩提树下的杨过
2018/01/23
8160
WPF --- 触摸屏下的两个问题
具体场景就是一个配置界面, ScrollViewer 中包含一个StackPanel 然后纵向堆叠,以滚动的方式查看,然后包含多个 TextBlock 、 TextBox 以及DataGrid ,期间遇到了两个问题:
Niuery Diary
2024/03/13
2380
WPF --- 触摸屏下的两个问题
win10 uwp listView 绑定前一项 WPF 绑定前一项UWP 绑定前一项
大神问,如何在 ListView 绑定前一项,于是我下面告诉大家如何在 ListView 绑定前一项
林德熙
2018/09/18
9770
如何实现日期范围选择器
原文链接: https://github.com/WPFDevelopersOrg/WPFDevelopers
郑子铭
2024/12/20
1040
如何实现日期范围选择器
Silverlight Telerik控件学习:数据录入、数据验证
相信很多人都听说过这句名言:garbage in ,garbage out ! 数据录入不规范(或错误)就象一颗定时炸弹,迟早会给系统带来麻烦,所以在数据录入时做好验证是很有必要的。 相对传统asp.net开发而言,SL4中的数据验证要轻松很多(主要得益于Xaml的Binding特性),步骤如下: 1、定义业务Model类时,在需要验证的属性setter中,写好业务逻辑,对于不合规范的value,要抛出异常! 同时切记Model类要实现INotifyPropertyChanged接口,同时每个setter方
菩提树下的杨过
2018/01/23
3K0
Silverlight Telerik控件学习:数据录入、数据验证
[WPF自定义控件库]好用的VisualTreeExtensions
A long time ago in a galaxy far, far away....微软在Silverlight Toolkit里提供了一个好用的VisualTreeExtensions,里面提供了一些查找VisualTree的扩展方法。在那个时候(2009年),VisualTreeExtensions对我来说正好是个很棒的Linq和扩展方法的示例代码,比那时候我自己写的FindChildByName之类的方法好用一万倍,所以我印象深刻。而且因为很实用,所以我一直在用这个类(即使是在WPF中),而这次我也把它添加到Kino.Wpf.Toolkit中,可以在 这里 查看源码。
dino.c
2019/07/12
1.2K0
[WPF自定义控件库]好用的VisualTreeExtensions
Silverlight Telerik控件学习:GridView双向绑定
做过WinForm数据库开发的人,一定有类似经历:DataGrid绑定后,如果允许行编辑,数据一顿修改后,想批量保存修改后的结果,通常是将DataGrid的所有行遍历,用FindControl找出其中的TextBox之类的控件,取值,然后处理,如果行模板中的控件变化了,可能之前的处理代码又要修改... .Net发展到WPF/SL时代,有了双向绑定,这种痛苦经历已经一去不返了,我们只需要关注数据即可,GridView与数据源之间会相互通知各自的变化情况,批量保存时,不管GridView中的数据用户如何修改,也
菩提树下的杨过
2018/01/23
9310
Silverlight Telerik控件学习:GridView双向绑定
WPF实现列表分页控件的示例代码分享
[TemplatePart(Name = CountPerPageTextBoxTemplateName, Type = typeof(TextBox))]
用户7718188
2022/11/06
1.3K0
推荐阅读
相关推荐
dotnet UNO 如何在调试下输出界面层级结构
更多 >
领券
社区富文本编辑器全新改版!诚邀体验~
全新交互,全新视觉,新增快捷键、悬浮工具栏、高亮块等功能并同时优化现有功能,全面提升创作效率和体验
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文