Custom Ribbon Action (DownLoad Multiple File) -------------SharePoint 2010

【Claude Code · VibeCoding】11|需求梳理:云枢智学 / 学员平台 第三章 · 项目实战以「云枢智学」学员平台为例,把业务目标拆成可执行的需求条目。 阅读详情

http://www.cnblogs.com/KingStar/archive/2010/10/13/1850034.html

 

Below is a screenshot of my project :

 

The first thing I did was to create a new SharePoint 2010 Empty SharePoint Project called DeviantPoint.DownloadZip. Then, I added a reference to ICSharpCode.SharpZipLib.dll which is a part of SharpZipLib (a .NET library that is well-used for working with Zip files). I then created a helper class, ZipBuilder, used to actually create the zip file. I created this helper class with the intent that I could reuse this elsewhere, not just for this project.

Basically, when an instance of this class is constructed, you need to pass in a stream that will be used to write the contents of the zip file to. This could be any type stream (FileStream, MemoryStream, etc). There are a couple of helper methods in this class that allow you to add files and folders and method that “finalizes” the zip file. This Finalize() method must always be called to ensure that the zip file is written out correctly. This class also implements the IDisposable pattern since it is handling streams.

This is the code for the ZipBuilder class:

 

代码
using  System;
using  System.Collections.Generic;
using  System.Linq;
using  System.Text;
using  System.IO;
using  ICSharpCode.SharpZipLib.Zip;
using  ICSharpCode.SharpZipLib.Core;
namespace  SPMultipleFileDownLoad.Classes
{
    
public   class  ZipFileBuilder : IDisposable
    {
        
private   bool  disposed  =   false ;
        ZipOutputStream zipStream 
=   null ;
        
protected  ZipOutputStream ZipStream
        {
            
get  {  return  zipStream; }
        }
        ZipEntryFactory factory 
=   null ;
        
private  ZipEntryFactory Factory
        {
            
get  {  return  factory; }
        }
        
public  ZipFileBuilder(Stream outStream)
        {
            zipStream 
=   new  ZipOutputStream(outStream);
            zipStream.SetLevel(
9 );
            
// best compression  
            factory  =   new  ZipEntryFactory(DateTime.Now);
        }
        
public   void  Add( string  fileName, Stream fileStream)
        {
            
// create a new zip entry             
            ZipEntry entry  =  factory.MakeFileEntry(fileName);
            entry.DateTime 
=  DateTime.Now;
            ZipStream.PutNextEntry(entry);
            
byte [] buffer  =   new   byte [ 65536 ];
            
int  sourceBytes;
            
do
            {
                sourceBytes 
=  fileStream.Read(buffer,  0 , buffer.Length);
                ZipStream.Write(buffer, 
0 , sourceBytes);
            }
            
while  (sourceBytes  >   0 );
        }
        
public   void  AddDirectory( string  directoryName)
        {
            ZipEntry entry 
=  factory.MakeDirectoryEntry(directoryName);
            ZipStream.PutNextEntry(entry);
        }
        
public   void  Finish()
        {
            
if  ( ! ZipStream.IsFinished)
            {
                ZipStream.Finish();
            }
        }
        
public   void  Close()
        {
            Dispose(
true );
            GC.SuppressFinalize(
this );
        }
        
public   void  Dispose()
        {
            
this .Close();
        }
        
protected   virtual   void  Dispose( bool  disposing)
        {
            
if  ( ! disposed)
            {
                
if  (disposing)
                {
                    
if  (ZipStream  !=   null )
                        ZipStream.Dispose();
                }
            }
            disposed 
=   true ;
        }
    }
}

 

 

The next thing I wrote was SPExtensions.cs, a class for adding extension methods to some of the Microsoft.SharePoint objects. This class basically just adds a few simple helper methods to the SPListItem class and the SPList class. For the SPListItem class, I just added a method to determine if the SPListItem instance is actually a folder and for the SPList class, I added a method to determine if the list is actually a document library.

The code for SPExtensions is below:

 

 

代码
using  System;
using  System.Collections.Generic;
using  System.Linq;
using  System.Text;

// Add 
using  System.Runtime.CompilerServices;
using  Microsoft.SharePoint;

namespace  SPMultipleFileDownLoad.Classes
{
   
public   static   class  SPExtensions
    {
       
public   static   bool  IsFolder( this  SPListItem item)
       {
           
return  (item.Folder  !=   null );
       }
       
public   static   bool  IsDocumentLibrary( this  SPList list)
       {
           
return  (list.BaseType == SPBaseType.DocumentLibrary);
       }

    }
}

 

 

 

The next thing I did was to add a SharePoint Mapped Folder to my project mapping to the Layouts directory located in the SharePoint root. When you add a mapped folder, Visual Studio will automatically create a sub-folder in that mapped folder with the same name as your project. This is a good thing as you don’t want to be mixing up all your project files with all of the files that come out of the box from SharePoint.

After I had my Layouts mapped folder and subfolder created, I added a SharePoint 2010 Application Page item to the sub-folder called DownloadZip.aspx. The purpose of this application page is to actually handle the request from the client to build the zip file and send it back down to the client. Having an application page handle this is the same technique that is used with the ‘Download a Copy’ action button you see in the SharePoint 2010 ribbon. Basically, a POST request from a client is sent to my DownloadZip.aspx page and this page takes care of packaging up a zip file and sending it down to the client’s browser. This page expects two parameters:

  • sourceUrl –the full url of the document library (and folder, if inside of a subfolder) where the request is being made from
  • itemIDs – a semi-colon delimited list of the SPListItem IDs that should be included as part of the zip file. Note that folders also have ids so if a folder is selected, that folder’s id would also be sent.

The code-behind for this application page basically takes the list of item ids and for each item id, goes and grabs the corresponding file from the document library in SharePoint and, using the ZipBuilder class, packages it up as a zip file. If one of the items that was selected is actually a folder, it will create that folder in the zip file as well and put all the items that are in that SharePoint folder into the corresponding zip file folder. It will also traverse through all the sub-folders in the hierarchy.

Below is the code-behind for the DownloadZip.aspx application page (there is nothing I added to the Download.aspx file itself):

DownloadZip.aspx.cs

 

代码
using  System;
using  Microsoft.SharePoint;
using  Microsoft.SharePoint.WebControls;

using  System.IO;
using  System.Web;
using  SPMultipleFileDownLoad.Classes;


namespace  SPMultipleFileDownLoad.Layouts.SPMultipleFileDownLoad
{
    
public   partial   class  DownLoadZip : LayoutsPageBase
    {
        
protected   void  Page_Load( object  sender, EventArgs e)
        {
            
string  fullDocLibSourceUrl  =  Request.Params[ " sourceUrl " ];

            
if  ( string .IsNullOrEmpty(fullDocLibSourceUrl))  return ;
            
string  docLibUrl  =  fullDocLibSourceUrl.Replace(SPContext.Current.Site.Url,  "" );
            SPList list 
=  SPContext.Current.Web.GetList(docLibUrl);
            
if  ( ! list.IsDocumentLibrary())  return ;
            
string  pItemIds  =  Request.Params[ " itemIDs " ];

            
if  ( string .IsNullOrEmpty(pItemIds))  return ;
            SPDocumentLibrary library 
=  (SPDocumentLibrary)list;

            
string [] sItemIds  =  pItemIds.Split( new   char [] {  ' ; '  }, StringSplitOptions.RemoveEmptyEntries);
            
int [] itemsIDs  =   new   int [sItemIds.Length];
            
for  ( int  i  =   0 ; i  <  sItemIds.Length; i ++ )
            {
                itemsIDs[i] 
=  Convert.ToInt32(sItemIds[i]);
            }
            
if  (itemsIDs.Length  >   0 )
            {
                
using  (MemoryStream ms  =   new  MemoryStream())
                {
                    
using  (ZipFileBuilder builder  =   new  ZipFileBuilder(ms))
                    {
                        
foreach  ( int  id  in  itemsIDs)
                        {
                            SPListItem item 
=  library.GetItemById(id);
                            
if  (item.IsFolder())
                                AddFolder(builder, item.Folder, 
string .Empty);
                            
else
                                AddFile(builder, item.File, 
string .Empty);
                        }
                        builder.Finish();
                        WriteStreamToResponse(ms);
                    }
                }
            }
        }


        
private   static   void  AddFile(ZipFileBuilder builder, SPFile file,  string  folder)
        {
            
using  (Stream fileStream  =  file.OpenBinaryStream())
            {
                builder.Add(folder 
+   " // "   +  file.Name, fileStream);

                fileStream.Close();
            }
        }
        
private   void  AddFolder(ZipFileBuilder builder, SPFolder folder,  string  parentFolder)
        {
            
string  folderPath  =  parentFolder  ==   string .Empty  ?  folder.Name : parentFolder  +   " // "   +  folder.Name;
            builder.AddDirectory(folderPath);
            
foreach  (SPFile file  in  folder.Files)
            {
                AddFile(builder, file, folderPath);
            }
            
foreach  (SPFolder subFolder  in  folder.SubFolders)
            {
                AddFolder(builder, subFolder, folderPath);
            }
        }

        
private   void  WriteStreamToResponse(MemoryStream ms)
        {
            
if  (ms.Length  >   0 )
            {
                
string  filename  =  DateTime.Now.ToFileTime().ToString()  +   " .zip " ;
                Response.Clear();
                Response.ClearHeaders();
                Response.ClearContent();
                Response.AddHeader(
" Content-Length " , ms.Length.ToString());
                Response.AddHeader(
" Content-Disposition " ,  " attachment; filename= "   +  filename);
                Response.ContentType 
=   " application/octet-stream " ;
                
byte [] buffer  =   new   byte [ 65536 ];
                ms.Position 
=   0 ;
                
int  num;
                
do
                {
                    num 
=  ms.Read(buffer,  0 , buffer.Length);
                    Response.OutputStream.Write(buffer, 
0 , num);
                }
                
while  (num  >   0 );
                Response.Flush();

            }
        }
    }
}



 

 

After creating the application page, I added a SharePoint 2010 Empty Element item called DownloadZip to my project. This is nothing more than an Elements.xml file that takes care of adding my custom action to ribbon (CustomAction.Location=”CommandUI.Ribbon”). By default, for document libraries, this is what the ribbon looks like:

image

I wanted to add my action inside of the area in the Documents tab, inside of the Copies group so to do this, for the CommandUIDefinition, I set the Location attribute to "Ribbon.Documents.Copies.Controls._children”. I also wanted it to appear right after the Download a Copy action so for the Button element’s Sequence attribute, I set the value to 15 (the Download a Copy button has a sequence of 10 and the Send To button has a sequence of 20 so I needed to set the sequence of my button to something in between). To understand where everything is placed and what the sequences are by default, you need to look at the file C:/Program Files/Common Files/Microsoft Shared/Web Server Extensions/14/TEMPLATE/GLOBAL/XML/CMDUI.xml. I also specified the icons I wanted to use for my action (these icons are also part of my project, located in a sub-directory of the Images SharePoint mapped folder) and I also set the TemplateAlias to “o1” so that my icon shows up large like Download a Copy does. I also define the actual command handler in this Elements.xml file by adding a CommandUIHandler element. The CommandAction attribute is used to specify what exactly the button is supposed to do and the EnabledScript attribute is used to determine whether or not the button/command is enabled. These two attributes’ values both point to javascript functions I define in a separate file (discussed later). Because I’m using a separate javascript file, I also have to add another CustomAction element in the Elements file that points to the location of my javascript file. This is the result:

Enabled

image

Disabled

image

Below is the full Elements.xml file:

Elements.xml

 

 

代码
<? xml version="1.0" encoding="utf-8" ?>
< Elements  xmlns ="http://schemas.microsoft.com/sharepoint/" >
  
< CustomAction  Id ="DeviantPoint.DownloadZip"  Location ="CommandUI.Ribbon" >
    
< CommandUIExtension >
      
< CommandUIDefinitions >
        
< CommandUIDefinition  Location ="Ribbon.Documents.Copies.Controls._children" >
          
< Button  Id ="Ribbon.Documents.Copies.DownloadZip"      Command ="DownloadZip"      Sequence ="15"     Image16by16 ="/_layouts/images/DeviantPoint.DownloadZip/zip_16x16.png"
                  Image32by32
="/_layouts/images/SPMultipleFileDownLoad/zip.png"
                  Description
="Download zip"  LabelText ="Download as Zip"
                  TemplateAlias
="o1" />
        
</ CommandUIDefinition >
      
</ CommandUIDefinitions >
      
< CommandUIHandlers >
        
< CommandUIHandler    Command ="DownloadZip"    CommandAction ="javascript:downloadZip();"    EnabledScript ="javascript:enable();" />
      
</ CommandUIHandlers >
    
</ CommandUIExtension >
  
</ CustomAction >
  
< CustomAction  Id ="Ribbon.Library.Actions.Scripts"    Location ="ScriptLink"    ScriptSrc ="/_layouts/SPMultipleFileDownLoad/CustomActions.js"   />
</ Elements >

 

 

Finally, I created the CustomActions.js file. This file is used to define the actions/behavior of my new ribbon button. The enable() function is used to determine whether or not my button is enabled. If there is at least one item selected, then my button is enabled. The downloadZip() function just starts off the download process. Actually, I could have probably written the javascript so I didn’t even need this function or calls to SP.ClientContext.executeQueryAsync() but I was just trying to get something done quickly and actually writing it this way gave me another place to show-off another one of the UI features, the Status. If the call to SP.ClientContext.executeQueryAsync() fails, then the onQueryFailed delegate is executed. The onQueryFailed() function uses the SP.UI.Status to display the error message, shown here:

download_failed

The function onQuerySucceeded() is where the majority of the action happens. I use the SP.ListOperation.Selection object to get a list of the selected items. I then create a request to my DownloadZip.aspx application page and send that page the list of selected item ids as well as the current url (the url of the page the user is on). Like I said earlier, that application page takes care of packaging everything up as a zip and streaming it down to the browser.

Below is the code for CustomActions.js:

CustomActions.js

 

代码
function  enable()
 {  
    
var  items  =  SP.ListOperation.Selection.getSelectedItems();   
     
var  itemCount  =  CountDictionary(items); 
       
return  (itemCount  >   0 );   
 }  
 
function  downloadZip() 
 {    
      
var  context  =  SP.ClientContext.get_current();  
      
this .site  =  context.get_site();  
      
this .web  =  context.get_web();  
      context.load(
this .site);  
      context.load(
this .web);  
      context.executeQueryAsync(  
      Function.createDelegate(
this ,  this .onQuerySucceeded),
      Function.createDelegate(
this ,  this .onQueryFailed)      );   }  
      
function  onQuerySucceeded() 
      {  
       
var  items  =  SP.ListOperation.Selection.getSelectedItems();  
       
var  itemCount  =  CountDictionary(items);  
       
if  (itemCount  ==   0 )  return ;  
       
var  ids  =   "" ; 
       
for  ( var  i  =   0 ; i  <  itemCount; i ++ )
       {      
           ids 
+=  items[i].id  +   " ; " ;  
       }  
         
// send a request to the zip aspx page.  
         var  form  =  document.createElement( " form " );  
        form.setAttribute(
" method " ,  " post " );  
         form.setAttribute(
" action " ,  this .site.get_url()  +   this .web.get_serverRelativeUrl()  +   " /_layouts/SPMultipleFileDownLoad/downloadzip.aspx " ); 
        
var  hfSourceUrl  =  document.createElement( " input " ); 
         hfSourceUrl.setAttribute(
" type " ,  " hidden " );  
         hfSourceUrl.setAttribute(
" name " ,  " sourceUrl " );  
         hfSourceUrl.setAttribute(
" value " , location.href); 
         form.appendChild(hfSourceUrl); 
         
var  hfItemIds  =  document.createElement( " input " )  
         hfItemIds.setAttribute(
" type " ,  " hidden " );  
         hfItemIds.setAttribute(
" name " ,  " itemIDs " );  
         hfItemIds.setAttribute(
" value " , ids);  
         form.appendChild(hfItemIds);  
         document.body.appendChild(form); 
         form.submit();  
       }  
       
function  onQueryFailed(sender, args) 
         {  
             
this .statusID  =  SP.UI.Status.addStatus( " Download as Zip: " ,   " Downloading Failed:  "   +  args.get_message()  +   "  <a href='#' onclick='javascript:closeStatus();return false;'>Close</a>. " ,  true );  
            SP.UI.Status.setStatusPriColor(
this .statusID,  " red " );  
      }   

 

 

So how does this actually all look when the user is using it? Below is the hierarchy of an example document library I have:

image

  • Documents
    • Folder A (Folder)
      • Subfolder in Folder A (Folder)
        • Sub Sub Folder (Folder)
          • Versioning Flow (Visio diagram)
        • Business Brief_SoW (Word document)
        • SoW_Phase1 (Word document)
      • Request Email (Text file)
      • Users and Roles (Excel file)
    • Issues (Excel file)
    • Product_Planning (Excel file)

The user has selected some documents and a sub-folder so my custom ribbon button is enabled:

image

The user clicks on this button and this feature executes and after it’s complete the user is prompted with this (note, the filename is a timestamp):

image

 

Reference :http://www.deviantpoint.com/post/2010/05/08/SharePoint-2010-Download-as-Zip-File-Custom-Ribbon-Action.aspx

史上最强量化工具库 Ta-Lib 从入门到精通,一篇文章就够了! Ta-Lib 提供的 13 个关键指标,并配上详细的代码示例,确保你看完就能直接上手!🔥。 阅读详情

相关推荐

手把手调试Android 14 ShellTransitions:用Log追踪ActiveTransition与Handler匹配过程

本文详细介绍了在Android 14中调试ShellTransitions机制的方法,重点通过Log追踪ActiveTransition与Handler的匹配过程。文章提供了关键日志点植入策略、Handler匹配机制解析及实战调试案例,帮助开发者解决窗口转场动画中的卡顿和错乱问题,提升系统动画性能。

weixin_42652674的博客 429

C# 压缩目录

保存目录结构 ZipHelper帮助类 public class ZipHelper { public static readonly FastZip Instance = new FastZip(); /// <summary> /// 自动包含子目录,压缩文件夹 window 资源管理不能直接打开 /// </summary> /// <param name="dirToZip"></param> /// <param name=

闪耀星星的窝 609

模拟CMOS 第2章 MOS器件物理基础

模拟CMOS 第2章 MOS器件物理基础 文章目录模拟CMOS 第2章 MOS器件物理基础2.1 基本概念2.1.1 MOSEFT开关2.1.2 MOSEFT结构2.1.3 MOS符号2.2 MOS的I/V特性2.2.1 阈值电压2.2.2 I/V特性的推导2.3 二级效应2.4 MOS器件模型2.4.1 MOS器件版图2.4.2 MOS器件电容2.4.3 MOS小信号模型2.4.4 MOS SPICE模型2.4.5 NMOS与PMOS器件的比较2.4.6 长沟道器件与短沟道器件的比较附录A 用作电容器MO

椰子奶糖的博客 5196

SharePoint 2010中的客户端AJAX应用——对话框显示详细信息页

<br /> http://archive.cnblogs.com/a/1789846/ <br /> <br />本文是SharePoint 2010客户端AJAX应用系列的一部分。<br />ASP.Net AJAX模板是一门全新的引人注目的客户端技术,允许开发者快速构建AJAX易于维护的交互式应用程序。由于ASP.Net AJAX模板和SharePoint 2010都支持oData协议,因此两者结合在一起将是一个强大的组合。<br />SharePoint 2010 之所以可以带给人们Web 2.

AlwaysBeCoding的专栏 1357

从零构建工业级SPI-CAN网关:CH347与CH9431的软硬件协同设计实战

本文详细介绍了基于CH347和CH9431芯片构建工业级SPI-CAN网关的完整方案。通过硬件架构设计、Linux驱动定制、并发处理优化和EMC抗干扰测试,实现高可靠性通信网关,适用于工业自动化和汽车电子等严苛环境。

spark7igniter的博客 632

Dirsearch的下载、安装和使用(全)

Dirsearch工具的下载、安装和使用,超详细超全面

weixin_68416970的博客 1万+

React 性能:memo / useMemo / useCallback

讲清 memo/useMemo/useCallback 的配合与边界,先测量再优化,避开常见过早优化。

JudithHuang的博客 322

无法联网的情况下,dbeaver离线安装数据库驱动-clickhouse

无法联网的情况下,dbeaver离线安装数据库驱动-clickhouse

u012831187的博客 1万+

V8 机制、手写核心函数与 TypeScript 类型体操

或固定初始化(如数组先定长、对象先给全字段)保持类型与形状稳定;这些都比"换框架"更基础。只能处理纯数据(丢函数、Date、RegExp、循环引用报错)。生产级深拷贝要处理:原始值短路、循环引用、V8(Chrome / Node 的 JS 引擎)不是"解释一行跑一行"那么简单,它用。图:V8 执行流程——解释执行 + 热点优化,优化失败会 Deopt 回退。JS 内存自动管理,但"自动"不等于"不会漏"。是"固定间隔最多执行一次"。手写 Promise 是"懂异步"的试金石。是"停下后才执行最后一次",

qq_38468358的博客 328

1985-2021年30m全国逐年土地覆被数据(含分省数据)

基于CLCD,揭示了1985年至2019年期间中国土地覆被变化的趋势和模式,如不透水表面(+148.71%)和水(+18.39%)的扩大,耕地(-4.85%)和草地(-3.29%)的减少,以及森林(+4.34%)的增加。由于中国的一系列造林政策,如1980年代启动的三北防护林工程和2000年后启动的绿色增益工程,从1985年到 2019年,森林增加了4.34%,灌木减少了259万公顷,与 ESACCI_LC的减少趋势相似。尽管为了养活不断增长的人口,中国东北和西北地区进行了广泛的开垦,但耕地普遍减少。

J_Giser的博客 1469

PCL 快速均匀下采样

快速均匀下采样 是一种点云降采样技术,通过设置采样步长来实现等距降采样,从而减少点的数量。用户可以通过指定步长,选择每隔一定数量的点采样一个点,这样可以在保持点云几何特性的同时,显著减少点的数量。

纵马踏花向自由 870

Claude Code 从入门到实战(一):安装、登录与第一个Vue项目

Claude Code 系列实战第 1 篇:先认识 Claude Code 的工作方式与任务循环,完成 npm 安装、登录与授权,通过让 Claude 理解一个 Vue 项目完成第一次实战任务,并辨析默认、自动接受编辑、Plan 规划等权限模式的差异与选择策略。

weixin_45284808的博客 204

L3自动驾驶时代,域控制器核心解析(第一篇:架构演进与五域基础)

本文作为L3域控制器系列的第一篇,核心梳理了3个关键内容:L3时代为什么必须用域控制器:解决分布式ECU的协同、算力、迭代难题;域控制器的演进路线:从分布式ECU→域集中式→中央计算平台;博世五域架构的核心解析:五大域的定位、功能与典型方案。后续将持续更新系列文章,重点覆盖:第二篇:L3对域控制器的关键技术要求(传感器、算力、线控、软件、通信);第三篇:域控制器全产业链拆解(上游芯片、中游器件、下游总成);第四篇:域控制器的产业机遇与国产替代进展。

getusushu的博客 530

DSH (DeepSeek Harness) Windows 升级安装指南20261107

注意:如果在普通窗口执行 nvm 提示找不到命令,或执行 nvm use 提示 Access is denied,请务必关闭当前窗口,重新打开一个管理员CMD 执行上述完整路径命令。找到 .credentials.yaml,将其重命名为 .credentials.yaml.bak(备份并使其失效)。Node.js Storage Location:可改到非系统盘(如 D:\dev\nvm,避免路径含空格或中文)。打开文件资源管理器,进入 C:\Users<你的用户名>.dsh\。

fengye207161的博客 178

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

SpringBoot「衣依」服装销售平台:144个Java文件180个接口,从挑衣服到收货评价整条链路都在

# SpringBoot「衣依」服装销售平台:144个Java文件180个接口,从挑衣服到收货评价整条链路都在 > 这是一套基于 Spring Boot 的服装销售平台源码,配套 `db.sql` 建表脚本,业务覆盖商品展示、购物车、订单流转、收货地址、订单评价、商品评论、在线客服、轮播图和资讯。形态是**前后台双端**:前台是顾客逛的商城,后台是管理员管的控制台。本文带你看清里面有什么、怎么跑

面朝大海 221

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

微信小程序-wxs

在微信开发者工具中右键创建.wxs后缀的文件。每个.wxs文件也是一个独立模块,同样使用导出内容。示例(文件return d;FOO: foo,bar: bar(外联定义参考官方文档)

dreams_dream的博客 328

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

使用echarts模拟甘特图

项目中需按时间段展示不同颜色的数据,通过解析时长并统计各类型总时长,结合预设颜色映射表(含自定义与默认色),动态生成ECharts图表。利用sumByTypeName聚合数据,为每类分配对应颜色,实现图例与柱状图的精准匹配,确保多时段、多类型数据可视化清晰准确。

uuai 25

【技术专题】JavaScript 网页技术 - JavaScript 流程控制

小锋老师推出《一天学会JavaScript(无废话版)》视频教程,涵盖基础语法、流程控制、函数、数组对象、DOM操作及ES6新特性。内容精炼,配套课件与源码打包下载,助力快速入门。重点讲解if/else、switch、for/while循环、for...of/in遍历及break/continue使用场景,并通过成绩判断实例演示实际应用。适合零基础学习者高效掌握核心技能。

java1234的博客 143

基于 FastAPI+LangChain+LangGraph+Agent+Vue3+MySQL 的房产数据采集与房价预测分析平台

本文介绍一个完整的「房产数据采集+AI房价预测」全栈项目,涵盖FastAPI异步后端、LangGraph Agent智能问答、爬虫采集、机器学习预测与Vue3前端,实现从数据采集到AI交互的闭环。项目融合多技术栈,具备真实业务场景与生产级设计(如降级策略、流式输出、多模型对比),兼具简历亮点与答辩演示优势,可系统性提升工程能力,并附高频面试题解析,是理想的技术综合实践项目。

深耕开发,专注编程实战。分享源码解析、项目搭建、问题排查笔记,沉淀技术,持续更新。 211

Agent 的 ReAct、Plan、Execute、Reflection 模式

本文系统解析 Agent 的 ReAct、Plan、Execute、Reflection 四模式,揭示其核心为“下一步谁定”与“错了怎么发现”两大问题。ReAct 逐步决策,适合动态环境但易冗余;Plan 一次性规划,高效却惧变化;Execute 严格落地,需明确判据与失败策略;Reflection 事后校验,强化纠错闭环。四者协同:外层规划,执行中嵌入思考,每步后反思,连续失败才重规划,构建稳定可控的智能体工作流。

2401_89855466的博客 319

货运APP、货运小程序开发:网络货运平台与同城配送搬家系统实战

本文介绍一套完整的货运平台系统,涵盖货运APP、小程序、网络货运、同城配送、搬家预约等场景,基于SpringBoot+MyBatisPlus+MySQL技术栈,采用uni-app实现多端统一开发,配套TMS运输管理与物流管理系统,支持下单、派单、运输、结算全流程,适用于货运搬家、物流搬运与配送业务,可作为物流软件及TMS系统的参考实现。

juzige03的博客 216

Vue3 低代码移动表单设计器实战(二):缩放画布下的拖拽系统与树状级联数据结构

本文深入剖析Vue3低代码表单设计器在缩放画布下的拖拽失效问题,揭示SortableJS在CSS Transform下坐标崩溃的数学根源。通过自研独立视觉克隆壳层与逆向几何补偿算法,实现精准拖拽;采用扁平数据存储+运行时树状计算结构,解决级联依赖与深克隆难题,确保逻辑一致性与性能优化,为复杂低代码系统提供可复用的工程范式。

NanChen的博客 337

Vue-Router

本文详解前端路由原理与实现,以网易云音乐为例,介绍通过 vue-router 实现页面无刷新切换。核心步骤包括:安装模块、创建路由实例、注册应用、配置页面组件与路由出口。使用 router-link 实现声明式导航,结合 query 和 params 传参,支持模糊与精确匹配激活状态。强调 useRoute(读取参数)与 useRouter(执行跳转)的区别,帮助开发者掌握单页应用路由的核心机制。

2301_79245606的博客 336

LangGraph == 循环结构的实现

这是静态约束,不会参与运行时校验。主要作用是提升代码可读性、通过静态类型检查,同时帮助 LangGraph。也就是说,是否继续重试,在当前实现中主要由大模型决定,而不是由程序逻辑强制保证。因此,如果模型在多次工具调用失败后选择停止重试并生成最终回答,运行图不会阻止它。函数,也不再需要调用 add_conditional_edges()只要大模型持续返回工具调用,流程就会不断回到 llm_node。的缩写,即“推理 + 行动”架构。,运行时只负责判断具体走哪一条路径。

每天都要努力学习哦~~ 344

Vue 前端开发 AI 对话页面:流式消息渲染、文件上传

关键点是不能手动设置 Content-Type 为 multipart/form-data,必须由浏览器自动生成带有 boundary 的请求头,否则后端无法解析。思路:将对象序列化为 JSON 字符串,作为 FormData 的一个普通字段(如 formData.append(‘payload’, JSON.stringify(data))),后端接收该字段后再反序列化。若上传大文件(>10MB),需实现独立的分片上传接口,在提交对话前先获取文件 id 或 url,再随文本发送引用。移除输入框的禁用态;

2402_85729970的博客 382
上一篇: Disabling Mobile Web Page Access in SharePoint Server 2010 and SharePoint Foundation 2010
下一篇: SharePoint 2010中的客户端AJAX应用——对话框显示详细信息页
SseJava
博客等级 码龄23年 7粉丝 9原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值