您目前尚未登陆,请选择【登陆】或【注册
首页->上传下载->51aspx大文件上传并显示进度和上传速率示例及组建源码>>WebbUpload/WebbHelper.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:51aspx大文件上传并显示进度和上传速率示例及组建源码
当前文件:文件类型 LargeFileUpload/WebbUpload/WebbHelper.cs打开代码结构图
普通视图
		            
1using System; 2using System.IO; 3using System.Text; 4using System.Web; 5 6namespace Webb.WAVE.Controls.Upload 7{ 8 ////该源码下载自www.51aspx.com(51aspx.com) 9 10 internal class WebbHelper 11 { 12 Fields 18 19 Constructors 30 31 /// <summary> 32 /// return the current httpcontext object. 33 /// </summary> 34 /// <returns></returns> 35 public static HttpContext GetContext() 36 { 37 HttpContext context = HttpContext.Current; 38 if (context == null) 39 { 40 throw new Exception("HttpContext not found"); 41 } 42 return context; 43 } 44 45 /// <summary> 46 /// return the current version of assembly. 47 /// </summary> 48 /// <returns></returns> 49 public static string GetVersion() 50 { 51 if (WebbHelper.version == null) 52 { 53 int majorVersion = typeof (WebbHelper).Assembly.GetName().Version.Major; 54 WebbHelper.version = majorVersion.ToString(); 55 } 56 return WebbHelper.version; 57 } 58 59 /// <summary> 60 /// Return the path of upload folder. 61 /// </summary> 62 /// <returns></returns> 63 public static string GetUploadFolder() 64 { 65 string uploadFolder = GetContext().Request["Webb_Upload_TempPath"]; 66 //If upload folder deos not exist, use system temporary folder to hold the file. 67 if ((uploadFolder == null) || (uploadFolder == string.Empty)||!Directory.Exists(uploadFolder)) 68 { 69 uploadFolder = Path.GetTempPath(); 70 } 71 return uploadFolder; 72 } 73 74 /// <summary> 75 /// Load file from chache. 76 /// </summary> 77 /// <param name="filename"></param> 78 /// <returns></returns> 79 private static byte[] LoadFileFromCache(string i_filename) 80 { 81 byte[] m_buffer; 82 HttpContext m_context = GetContext(); 83 if(m_context.Cache[RESOURCE_FILE_PREFIX + i_filename] == null) 84 { 85 m_context.Cache[RESOURCE_FILE_PREFIX + i_filename] = LoadAssemblyFiles(i_filename); 86 } 87 m_buffer = (byte[])m_context.Cache[RESOURCE_FILE_PREFIX + i_filename]; 88 return m_buffer; 89 } 90 91 /// <summary> 92 /// Load file from assembly. 93 /// </summary> 94 /// <param name="fileName"></param> 95 /// <returns></returns> 96 public static byte[] LoadAssemblyFiles(string i_filename) 97 { 98 if (i_filename == null) 99 { 100 throw new ArgumentNullException("i_filename"); 101 } 102 string fullFileName = RESOURCE_FILE_PREFIX + i_filename; 103 byte[] m_fileContent; 104// using(Stream stream=typeof(WebbHelper).Assembly.GetManifestResourceStream(i_filename)) 105// { 106// m_fileContent = new byte[stream.Length]; 107// stream.Read(m_fileContent, 0, m_fileContent.Length); 108// } 109 Stream stream = typeof(WebbHelper).Assembly.GetManifestResourceStream(fullFileName); 110 m_fileContent = new byte[stream.Length]; 111 stream.Read(m_fileContent, 0, m_fileContent.Length); 112 stream.Close(); 113 return m_fileContent; 114 } 115 116 /// <summary> 117 /// Get html template from buildin resource file 118 /// </summary> 119 /// <param name="filename"></param> 120 /// <returns></returns> 121 public static StringBuilder GetHtml(string filename) 122 { 123 byte[] buffer = LoadFileFromCache(filename); 124 if (buffer == null) 125 { 126 throw new ArgumentNullException("filename", ("isn't find " + filename)); 127 } 128 if (buffer.Length == 0) 129 { 130 throw new ArgumentNullException("filename", ("isn't find " + filename)); 131 } 132 return new StringBuilder(Encoding.Default.GetString(buffer)); 133 } 134 135 /// <summary> 136 /// Return true if client browser > IE 5.5 137 /// </summary> 138 /// <returns></returns> 139 public static bool IsAccordantBrowser() 140 { 141 HttpBrowserCapabilities bc = GetContext().Request.Browser; 142 if(bc.Browser != "IE" || float.Parse(bc.Version) < 5.5 ) 143 { 144 return false; 145 } 146 return true; 147 } 148 149 /// <summary> 150 /// Turn file size into a readability format. 151 /// </summary> 152 /// <param name="size"></param> 153 /// <returns></returns> 154 public static string GetFormatString(double size) 155 { 156 string sizeString; 157 if (size >= 1048576) 158 { 159 sizeString = (Math.Round(size/1048576, 2)+" MB"); 160 } 161 else if (size >= 1024) 162 { 163 sizeString = (Math.Round(size/1024, 2)+" KB"); 164 } 165 else 166 { 167 sizeString = (size+" B"); 168 } 169 return sizeString; 170 } 171 /// <summary> 172 /// Turn time string into a readability format. 173 /// </summary> 174 /// <param name="span"></param> 175 /// <returns></returns> 176 public static string GetFormatString(TimeSpan span) 177 { 178 string timeString=string.Empty; 179 if ((span.Days>0) || (span.Hours>0)) 180 { 181 int hours = ((0x18*span.Days) + span.Hours); 182 timeString = (timeString + hours + "&nbsp;Hour(s)&nbsp;"); 183 } 184 if (span.Minutes>0) 185 { 186 timeString = (timeString + span.Minutes + "&nbsp;Minute(s)&nbsp;"); 187 } 188 if (span.Seconds>0) 189 { 190 timeString = (timeString + span.Seconds + "&nbsp;Second(s)&nbsp;"); 191 } 192 return timeString; 193 } 194 } 195}
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:51aspx大文件上传并显示进度和上传速率示例及组建源码
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号