iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >telerik upload 在silv
  • 572
分享到

telerik upload 在silv

telerikuploadsilv 2023-01-31 01:01:51 572人浏览 独家记忆

Python 官方文档:入门教程 => 点击学习

摘要

打开SL工程添加引用Telerik.windows.Controls.dll and Telerik.Windows.Controls.Input.dll. 以及在Page.xaml中添加RadUpload控件 <

打开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;
    }
}

--结束END--

本文标题: telerik upload 在silv

本文链接: https://www.lsjlt.com/news/183368.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • telerik upload 在silv
    打开SL工程添加引用Telerik.Windows.Controls.dll and Telerik.Windows.Controls.Input.dll. 以及在Page.xaml中添加RadUpload控件 <...
    99+
    2023-01-31
    telerik upload silv
  • 如何在ElementUI的上传组件el-upload中设置header
    目录在ElementUI上传组件el-upload中设置headerelement-ui中的upload组件使用总结在ElementUI上传组件el-upload中设置header ...
    99+
    2024-04-02
  • 组件中多个el-upload存在导致上传图片失效问题怎么解决
    本篇内容介绍了“组件中多个el-upload存在导致上传图片失效问题怎么解决”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!组件中多个el-u...
    99+
    2023-07-05
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作