- 浏览: 284562 次
- 性别:
- 来自: 深圳
-
文章分类
最新评论
-
iceblue123:
厉害,太感谢楼主了,第二种方法威武!
spring MVC 3.2中@ResponseBody返回乱码的完美解决方案 -
gaozi131:
感谢啊 折腾了一下午搞定
spring MVC 3.2中@ResponseBody返回乱码的完美解决方案 -
yenshen:
找了半天,问题终于解决了,感谢!
spring MVC 3.2中@ResponseBody返回乱码的完美解决方案 -
笑闯天下:
感觉效率不是很高啊 ,如果从数据库中取到的数据 还要去自己拼接 ...
java导出CSV文件 -
ajonjun:
http://viralpatel.net/
解决ckeditor html不显示,ckeditor 自动过滤html
最近一直在研究 Smart Client 的 Smart Update 开发,从 Microsoft Updater Application Block v2.0 里面学到了很多东西,这里不得不佩服 Enterprise Library 的设计,设计模式和 XML 的运用使得 Enterprise Library 的扩展性很强,设计十分优美,是学习 OOP 的好范例。本人看了之后感叹自己写的代码大部分还是面向过程。
Enterprise Library 的广告就做到这里了,下面一个操作文件的工具类是从 Microsoft Updater Application Block v2.0 里面取出来的,感觉具有一定的参考价值,希望对大家有帮助。
Enterprise Library 的广告就做到这里了,下面一个操作文件的工具类是从 Microsoft Updater Application Block v2.0 里面取出来的,感觉具有一定的参考价值,希望对大家有帮助。
using System; using System.IO; using System.Runtime.InteropServices; namespace RapidTier { /// <summary> /// Indicates how to proceed with the move file operation. /// </summary> [Flags] public enum MoveFileFlag : int { /// <summary> /// Perform a default move funtion. /// </summary> None = 0x00000000, ///// <summary> /// If the target file exists, the move function will replace it. /// </summary> ReplaceExisting = 0x00000001, //// <summary> /// If the file is to be moved to a different volume, /// the function simulates the move by using the CopyFile and DeleteFile functions. /// </summary> CopyAllowed = 0x00000002, //// <summary> /// The system does not move the file until the operating system is restarted. /// The system moves the file immediately after AUTOCHK is executed, but before /// creating any paging files. Consequently, this parameter enables the function /// to delete paging files from previous startups. /// </summary> DelayUntilReboot = 0x00000004, //// <summary> /// The function does not return until the file has actually been moved on the disk. /// </summary> WriteThrough = 0x00000008, //// <summary> /// Reserved for future use. /// </summary> CreateHardLink = 0x00000010, //// <summary> /// The function fails if the source file is a link source, but the file cannot be tracked after the move. This situation can occur if the destination is a volume formatted with the FAT file system. /// </summary> FailIfNotTrackable = 0x00000020, } //// <summary> /// Provides certain utilities used by configuration processors, such as correcting file paths. /// </summary> public sealed class FileUtility { Constructor#region Constructor //// <summary> /// Default constructor. /// </summary> private FileUtility() { } #endregion Public members#region Public members //// <summary> /// Returns whether the path is a UNC path. /// </summary> /// <param name="path">The path string.</param> /// <returns><c>true</c> if the path is a UNC path.</returns> public static bool IsUncPath( string path ) { // FIRST, check if this is a URL or a UNC path; do this by attempting to construct uri object from it Uri url = new Uri( path ); if( url.IsUnc ) { // it is a unc path, return true return true; } else { return false; } } //// <summary> /// Takes a UNC or URL path, determines which it is (NOT hardened against bad strings, assumes one or the other is present) /// and returns the path with correct trailing slash: backslash for UNC or /// slash mark for URL. /// </summary> /// <param name="path">The URL or UNC string.</param> /// <returns>Path with correct terminal slash.</returns> public static string AppendSlashUrlOrUnc( string path ) { if( IsUncPath( path ) ) { // it is a unc path, so decorate the end with a back-slash (to correct misconfigurations, defend against trivial errors) return AppendTerminalBackslash( path ); } else { // assume URL here return AppendTerminalForwardSlash( path ); } } //// <summary> /// If not present appends terminal backslash to paths. /// </summary> /// <param name="path">A path string; for example, "C:\AppUpdaterClient".</param> /// <returns>A path string with trailing backslash; for example, "C:\AppUpdaterClient\".</returns> public static string AppendTerminalBackslash( string path ) { if( path.IndexOf( Path.DirectorySeparatorChar, path.Length - 1 ) == -1 ) { return path + Path.DirectorySeparatorChar; } else { return path; } } //// <summary> /// Appends a terminal slash mark if there is not already one; returns corrected path. /// </summary> /// <param name="path">The path that may be missing a terminal slash mark.</param> /// <returns>The corrected path with terminal slash mark.</returns> public static string AppendTerminalForwardSlash( string path ) { if( path.IndexOf( Path.AltDirectorySeparatorChar, path.Length - 1 ) == -1 ) { return path + Path.AltDirectorySeparatorChar; } else { return path; } } //// <summary> /// Creates a new temporary folder under the system temp folder /// and returns its full pathname. /// </summary> /// <returns>The full temp path string.</returns> public static string CreateTemporaryFolder() { return Path.Combine( Path.GetTempPath(), Path.GetFileNameWithoutExtension( Path.GetTempFileName() ) ); } //// <summary> /// Copies files from the source to destination directories. Directory.Move is not /// suitable here because the downloader may still have the temporary /// directory locked. /// </summary> /// <param name="sourcePath">The source path.</param> /// <param name="destinationPath">The destination path.</param> public static void CopyDirectory( string sourcePath, string destinationPath ) { CopyDirectory( sourcePath, destinationPath, true ); } //// <summary> /// Copies files from the source to destination directories. Directory.Move is not /// suitable here because the downloader may still have the temporary /// directory locked. /// </summary> /// <param name="sourcePath">The source path.</param> /// <param name="destinationPath">The destination path.</param> /// <param name="overwrite">Indicates whether the destination files should be overwritten.</param> public static void CopyDirectory( string sourcePath, string destinationPath, bool overwrite ) { CopyDirRecurse( sourcePath, destinationPath, destinationPath, overwrite ); } //// <summary> /// Move a file from a folder to a new one. /// </summary> /// <param name="existingFileName">The original file name.</param> /// <param name="newFileName">The new file name.</param> /// <param name="flags">Flags about how to move the files.</param> /// <returns>indicates whether the file was moved.</returns> public static bool MoveFile( string existingFileName, string newFileName, MoveFileFlag flags) { return MoveFileEx( existingFileName, newFileName, (int)flags ); } //// <summary> /// Deletes a folder. If the folder cannot be deleted at the time this method is called, /// the deletion operation is delayed until the next system boot. /// </summary> /// <param name="folderPath">The directory to be removed</param> public static void DestroyFolder( string folderPath ) { try { if ( Directory.Exists( folderPath) ) { Directory.Delete( folderPath, true ); } } catch( Exception ) { // If we couldn't remove the files, postpone it to the next system reboot if ( Directory.Exists( folderPath) ) { FileUtility.MoveFile( folderPath, null, MoveFileFlag.DelayUntilReboot ); } } } //// <summary> /// Deletes a file. If the file cannot be deleted at the time this method is called, /// the deletion operation is delayed until the next system boot. /// </summary> /// <param name="filePath">The file to be removed</param> public static void DestroyFile( string filePath ) { try { if ( File.Exists( filePath ) ) { File.Delete( filePath ); } } catch { if ( File.Exists( filePath ) ) { FileUtility.MoveFile( filePath, null, MoveFileFlag.DelayUntilReboot ); } } } //// <summary> /// Clear up a folder. Delete all sub folders and files in the folder. /// </summary> /// <param name="folderPath">The directory to be cleared up</param> public static void ClearUpFolder( string folderPath ) { // Delete all sub folders string[] dirs = Directory.GetDirectories( folderPath ); for (int i = 0; i < dirs.Length; i++) { DestroyFolder( dirs[i] ); } // Delete all files string[] files = Directory.GetFiles( folderPath ); for (int i = 0; i < files.Length; i++) { DestroyFile( files[i] ); } } //// <summary> /// Returns the path to the newer version of the .NET Framework installed on the system. /// </summary> /// <returns>A string containig the full path to the newer .Net Framework location</returns> public static string GetLatestDotNetFrameworkPath() { Version latestVersion = null; string fwkPath = Path.GetFullPath( Path.Combine( Environment.SystemDirectory, @"..\Microsoft.NET\Framework" ) ); foreach(string path in Directory.GetDirectories( fwkPath, "v*" ) ) { string candidateVersion = Path.GetFileName( path ).TrimStart( 'v' ); try { Version curVersion = new Version( candidateVersion ); if ( latestVersion == null || ( latestVersion != null && latestVersion < curVersion ) ) { latestVersion = curVersion; } } catch {} } return Path.Combine( fwkPath, "v" + latestVersion.ToString() ); } #endregion Private members#region Private members //// <summary> /// API declaration of the Win32 function. /// </summary> /// <param name="lpExistingFileName">Existing file path.</param> /// <param name="lpNewFileName">The file path.</param> /// <param name="dwFlags">Move file flags.</param> /// <returns>Whether the file was moved or not.</returns> [DllImport("KERNEL32.DLL")] private static extern bool MoveFileEx( string lpExistingFileName, string lpNewFileName, long dwFlags ); //// <summary> /// Utility function that recursively copies directories and files. /// Again, we could use Directory.Move but we need to preserve the original. /// </summary> /// <param name="sourcePath">The source path to copy.</param> /// <param name="destinationPath">The destination path to copy to.</param> /// <param name="originalDestination">The original dstination path.</param> /// <param name="overwrite">Whether the folders should be copied recursively.</param> private static void CopyDirRecurse( string sourcePath, string destinationPath, string originalDestination, bool overwrite ) { // ensure terminal backslash sourcePath = FileUtility.AppendTerminalBackslash( sourcePath ); destinationPath = FileUtility.AppendTerminalBackslash( destinationPath ); if ( !Directory.Exists( destinationPath ) ) { Directory.CreateDirectory( destinationPath ); } // get dir info which may be file or dir info object DirectoryInfo dirInfo = new DirectoryInfo( sourcePath ); string destFileName = null; foreach( FileSystemInfo fsi in dirInfo.GetFileSystemInfos() ) { if ( fsi is FileInfo ) { destFileName = Path.Combine( destinationPath, fsi.Name ); // if file object just copy when overwrite is allowed if ( File.Exists( destFileName ) ) { if ( overwrite ) { File.Copy( fsi.FullName, destFileName, true ); } } else { File.Copy( fsi.FullName, destFileName ); } } else { // avoid this recursion path, otherwise copying directories as child directories // would be an endless recursion (up to an stack-overflow exception). if ( fsi.FullName != originalDestination ) { // must be a directory, create destination sub-folder and recurse to copy files //Directory.CreateDirectory( destinationPath + fsi.Name ); CopyDirRecurse( fsi.FullName, destinationPath + fsi.Name, originalDestination, overwrite ); } } } } #endregion } }
发表评论
-
20条ASP.NET常用语句非常实用
2009-12-22 23:39 13941.//弹出对话框.点击转向指定页面 Response.Wr ... -
C#/.NET主线程与子线程之间的关系
2009-12-22 23:10 2420以前一直没有在程序中写过总结,再翻开程序时却不知所云,所以我决 ... -
Using sqlite with .NET
2009-12-08 00:01 939The other day I found that ther ... -
C#操作Excel,套用模板并对数据进行分页
2009-12-07 23:52 2205using System; using System.I ... -
动态生成缩略图
2009-12-07 23:49 1364Util.cs 的部分代码: //// <summa ... -
如何获取客户IE统计信息
2009-12-07 23:47 1063namespace Huawei.com { p ... -
运用API函数获取系统信息
2009-12-07 23:44 1123<HTML> <HEAD> ... -
WMI类-所有可用的WMI的类封装
2009-12-07 23:43 1712public class WMIClasses ... -
自己写的一个文件上传的类
2009-12-07 23:42 1084using System; using System.C ... -
C# 检查字符串,防SQL注入攻击
2009-12-07 23:16 1852例子里暂定为=号和'号 bool CheckParams ... -
获取本机机器名和登录WINDOWS的用户名?
2009-12-07 23:13 3659using System; using System. ... -
C# 禁用ctrl+alt+del
2009-12-07 23:09 1890using System; using System.R ... -
获取应用程序进程实例,
2009-12-07 23:07 1319/// <summary> ... -
如何在C#中使用全局鼠标、键盘Hook
2009-12-07 23:03 2689今天,有个同事问我,怎样在C#中使用全局钩子?以前写的全局钩子 ... -
把Web Control导出为Excel或Word
2009-12-07 22:58 1055/// <summary> /// 将Web ... -
C#编程忘记密码功能的实现方法
2009-12-07 22:55 2409以下是引用片段: int result = user.Ge ... -
C#实现USB接口的程序代码
2009-12-07 22:53 1967namespace ConsoleApplication1 ... -
Textarea标签封装为Web在线编辑器
2009-12-07 22:42 1112Editor.htm <textarea style ... -
定自已的格式化类
2009-12-07 22:20 837public class Vector:IFormatta ... -
调用winapi中的FlashWindow
2009-12-07 22:18 14551.引用 using System.Runtime.In ...
相关推荐
python学习资源
jfinal-undertow 用于开发、部署由 jfinal 开发的 web 项目
基于Andorid的音乐播放器项目设计(国外开源)实现源码,主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者,也可作为课程设计、期末大作业。
python学习资源
python学习资源
python学习一些项目和资源
【毕业设计】java-springboot+vue家具销售平台实现源码(完整前后端+mysql+说明文档+LunW).zip
HTML+CSS+JavaScarip开发的前端网页源代码
python学习资源
【毕业设计】java-springboot-vue健身房信息管理系统源码(完整前后端+mysql+说明文档+LunW).zip
成绩管理系统C/Go。大学生期末小作业,指针实现,C语言版本(ANSI C)和Go语言版本
1_基于大数据的智能菜品个性化推荐与点餐系统的设计与实现.docx
【毕业设计】java-springboot-vue交流互动平台实现源码(完整前后端+mysql+说明文档+LunW).zip
内容概要:本文主要探讨了在高并发情况下如何设计并优化火车票秒杀系统,确保系统的高性能与稳定性。通过对比分析三种库存管理模式(下单减库存、支付减库存、预扣库存),强调了预扣库存结合本地缓存及远程Redis统一库存的优势,同时介绍了如何利用Nginx的加权轮询策略、MQ消息队列异步处理等方式降低系统压力,保障交易完整性和数据一致性,防止超卖现象。 适用人群:具有一定互联网应用开发经验的研发人员和技术管理人员。 使用场景及目标:适用于电商、票务等行业需要处理大量瞬时并发请求的业务场景。其目标在于通过合理的架构规划,实现在高峰期保持平台的稳定运行,保证用户体验的同时最大化销售额。 其他说明:文中提及的技术细节如Epoll I/O多路复用模型以及分布式系统中的容错措施等内容,对于深入理解大规模并发系统的构建有着重要指导意义。
基于 OpenCV 和 PyTorch 的深度车牌识别
【毕业设计-java】springboot-vue教学资料管理系统实现源码(完整前后端+mysql+说明文档+LunW).zip
此数据集包含有关出租车行程的详细信息,包括乘客人数、行程距离、付款类型、车费金额和行程时长。它可用于各种数据分析和机器学习应用程序,例如票价预测和乘车模式分析。
把代码放到Word中,通过开发工具——Visual Basic——插入模块,粘贴在里在,把在硅基流动中申请的API放到VBA代码中。在Word中,选择一个问题,运行这个DeepSeekV3的宏就可以实现在线问答
【毕业设计】java-springboot+vue机动车号牌管理系统实现源码(完整前后端+mysql+说明文档+LunW).zip
【毕业设计】java-springboot-vue交通管理在线服务系统的开发源码(完整前后端+mysql+说明文档+LunW).zip