zoukankan      html  css  js  c++  java
  • silverlight导入文件到WebService

    SL端代码
            private void btnSelectFile_Click(object sender, RoutedEventArgs e)
            {
                OpenFileDialog openFile 
    = new OpenFileDialog();
                openFile.Filter 
    = "Excel文件|*.xls";
                
    if (openFile.ShowDialog() == true)
                {
                    
    if (HtmlPage.Window.Confirm(string.Format("确定要导入“{0}”吗?", openFile.File.Name)))
                    {
                        KeywordServices.KeywordServicesSoapClient client 
    = SLHelpers.SoapClientFactory.CreateKeywordServicesSoapClient();
                        client.ImportExcelCompleted 
    += new EventHandler<KeywordServices.ImportExcelCompletedEventArgs>(client_ImportExcelCompleted);
                        Stream stream 
    = (Stream)openFile.File.OpenRead();
                        stream.Position 
    = 0;
                        
    byte[] buffer = new byte[stream.Length + 1];
                        stream.Read(buffer, 
    0, buffer.Length);

                        client.ImportExcelAsync(buffer);
                    }
                }
            }
    WebService端代码
            public bool ImportExcel(byte[] fileByte)
            {
                
    try
                {
                    
    string filePath = "c:\\a.xls";
                    FileStream stream 
    = new FileStream(filePath, FileMode.Create);
                    stream.Write(fileByte, 
    0, fileByte.Length);
                    stream.Close();

                    
    return true;
                }
                
    catch (Exception ex)
                {
                    
    //TODO:写日志
                      return false;
                }
            }
  • 相关阅读:
    IE6中overflow:hidden失效怎么办
    单例模式笔记
    linux 中的 "2>&1"含义
    linux 文件目录介绍
    centos 安装jdk
    SimpleDateFormat非线程安全
    Linux下Weblogic 11g R1安装和配置
    <meta>标签 的一些用法
    基于java的邮件群发软件
    史上最完整的集合类总结及hashMap遍历
  • 原文地址:https://www.cnblogs.com/yvesliao/p/1786183.html
Copyright © 2011-2022 走看看