﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>博客园-凄凉之地-最新评论</title><link>http://www.cnblogs.com/fengyishou/CommentsRSS.aspx</link><description>我正处于食物链的底层，正如园内众神所说，任何处于食物链底层的生物都只有等待灭亡。我要抗争，我不要做底层生物，我不要做蝼蚁！</description><language>zh-cn</language><pubDate>Fri, 16 Sep 2011 02:47:13 GMT</pubDate><lastBuildDate>Fri, 16 Sep 2011 02:47:13 GMT</lastBuildDate><generator>cnblogs</generator><item><title>Re:使用System.IO.Packaging.Package进行文件压缩所产生的问题</title><link>http://www.cnblogs.com/fengyishou/archive/2011/05/16/2043425.html#2097900</link><dc:creator>风疑</dc:creator><author>风疑</author><pubDate>Mon, 16 May 2011 03:16:55 GMT</pubDate><guid>http://www.cnblogs.com/fengyishou/archive/2011/05/16/2043425.html#2097900</guid><description><![CDATA[@Yong Zhang
其实，最终的解决方案和你所说的差不多，还是output管用。
ps：你说，如果在生成压缩的过程中，内存不够了咋办？<br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/fengyishou/" target="_blank">风疑</a> 2011-05-16 11:16 <a href="http://www.cnblogs.com/fengyishou/archive/2011/05/16/2043425.html#2097900#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Re:iColorPicker——最简单的jQuery颜色选择器</title><link>http://www.cnblogs.com/fengyishou/archive/2011/05/16/2025778.html#2097891</link><dc:creator>风疑</dc:creator><author>风疑</author><pubDate>Mon, 16 May 2011 03:12:42 GMT</pubDate><guid>http://www.cnblogs.com/fengyishou/archive/2011/05/16/2025778.html#2097891</guid><description><![CDATA[@Fish.John
嘘，这是博客园，别乱说话，会被笑话。园里大神很多的。<br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/fengyishou/" target="_blank">风疑</a> 2011-05-16 11:12 <a href="http://www.cnblogs.com/fengyishou/archive/2011/05/16/2025778.html#2097891#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Re:iColorPicker——最简单的jQuery颜色选择器</title><link>http://www.cnblogs.com/fengyishou/archive/2011/05/14/2025778.html#2096950</link><dc:creator>Fish.John</dc:creator><author>Fish.John</author><pubDate>Sat, 14 May 2011 14:09:10 GMT</pubDate><guid>http://www.cnblogs.com/fengyishou/archive/2011/05/14/2025778.html#2096950</guid><description><![CDATA[鹏哥，你的博客真的不赖……真好<br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/fengyishou/" target="_blank">Fish.John</a> 2011-05-14 22:09 <a href="http://www.cnblogs.com/fengyishou/archive/2011/05/14/2025778.html#2096950#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Re:使用System.IO.Packaging.Package进行文件压缩所产生的问题</title><link>http://www.cnblogs.com/fengyishou/archive/2011/05/12/2043425.html#2094967</link><dc:creator>Yong Zhang</dc:creator><author>Yong Zhang</author><pubDate>Thu, 12 May 2011 09:05:56 GMT</pubDate><guid>http://www.cnblogs.com/fengyishou/archive/2011/05/12/2043425.html#2094967</guid><description><![CDATA[@风疑
你的学习精神值得肯定！向你学习。具体到这个问题上面，你可能还自己多Debug一下，个人觉得这里面问题并不大，可以找出贵亏祸首。

“最终是返回的file，并不是直接使用的outputstream，而且在这个page的方法里，貌似只能是file流。”

public ActionResult DownLoad(int id) =&gt;DownLoad(int id, Response.OutputStream output)//把下载页面的Response传进来
==&gt; using (MemoryStream ms = new MemoryStream()) 就不需要了， 直接换成 output.

outputStream.Write(buffer, 0, bytesRead);
后面一定要 .Flush();
这样写入的数据就直接送到了网络上去去了。

按照我的理解，这样就不管多大的文件，多少人同时下载，应该都没有内存问题。
 


                

<br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/fengyishou/" target="_blank">Yong Zhang</a> 2011-05-12 17:05 <a href="http://www.cnblogs.com/fengyishou/archive/2011/05/12/2043425.html#2094967#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Re:使用System.IO.Packaging.Package进行文件压缩所产生的问题</title><link>http://www.cnblogs.com/fengyishou/archive/2011/05/12/2043425.html#2094886</link><dc:creator>风疑</dc:creator><author>风疑</author><pubDate>Thu, 12 May 2011 08:12:16 GMT</pubDate><guid>http://www.cnblogs.com/fengyishou/archive/2011/05/12/2043425.html#2094886</guid><description><![CDATA[@Yong Zhang
首先，感谢你的回复。
--------
最直观的就是，当下载的压缩包并不大时，大概在20-30M左右，没事。一旦在大点，就开始报错了。
-&gt; 内存引起的。如果一个用户下载 要30M，10个用户同时下载呢？

此时是单用户，还没考虑到多用户，不过估计同样会出错。

------
我在一台服务器上设置了everyone的权限，没事了，当去掉everyone的权限后，错误又出现了
--&gt; 我觉得和这个应该是没有关系，如果说有关系的话，那就是每次都会下载不成功，可能是没有读取文件的权限。总之这个有问题的话，出现的问题的现象不应该是你描述的那样。

问题确实是存在的，没有everyone权限的时候，下载小的文件时不会出错的，当然还是单用户。不过我估计可能会跟下面的问题有关联。
-------
个人的想法是：压缩包从内存流中读取，然后通过文件流进行写入，此时应当会产生一个临时文件，但是这个临时文件的大小是受限的，一旦太大
就无法继续进行写入了。从而关闭文件流
-&gt; 使用MemoryStream 肯定不会产生临时文件。

最终是返回的file，并不是直接使用的outputstream，而且在这个page的方法里，貌似只能是file流。
------
其实，我已经解决了，但是是用的另外一种方案，只不过我心里很纠结，想弄明白为什么这种方式会出错。
再次感谢你的回复。<br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/fengyishou/" target="_blank">风疑</a> 2011-05-12 16:12 <a href="http://www.cnblogs.com/fengyishou/archive/2011/05/12/2043425.html#2094886#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Re:使用System.IO.Packaging.Package进行文件压缩所产生的问题</title><link>http://www.cnblogs.com/fengyishou/archive/2011/05/12/2043425.html#2094443</link><dc:creator>Yong Zhang</dc:creator><author>Yong Zhang</author><pubDate>Thu, 12 May 2011 04:33:32 GMT</pubDate><guid>http://www.cnblogs.com/fengyishou/archive/2011/05/12/2043425.html#2094443</guid><description><![CDATA[最直观的就是，当下载的压缩包并不大时，大概在20-30M左右，没事。一旦在大点，就开始报错了。
-&gt; 内存引起的。如果一个用户下载 要30M，10个用户同时下载呢？

我在一台服务器上设置了everyone的权限，没事了，当去掉everyone的权限后，错误又出现了
--&gt; 我觉得和这个应该是没有关系，如果说有关系的话，那就是每次都会下载不成功，可能是没有读取文件的权限。总之这个有问题的话，出现的问题的现象不应该是你描述的那样。

个人的想法是：压缩包从内存流中读取，然后通过文件流进行写入，此时应当会产生一个临时文件，但是这个临时文件的大小是受限的，一旦太大
就无法继续进行写入了。从而关闭文件流
-&gt; 使用MemoryStream 肯定不会产生临时文件。

综上:
1) 仔细检查出问题的时候内存方面的情况。是一个用户引起的，还是多个用户同时操作引起的。
2）最佳的解决方案应该是边压缩，边下载。但是要注意，每次要stream.Flush, 这样就不会有问题了。你可以超这个思路去想，具体代码你自己在网上找找。







<br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/fengyishou/" target="_blank">Yong Zhang</a> 2011-05-12 12:33 <a href="http://www.cnblogs.com/fengyishou/archive/2011/05/12/2043425.html#2094443#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Re:使用System.IO.Packaging.Package进行文件压缩所产生的问题</title><link>http://www.cnblogs.com/fengyishou/archive/2011/05/12/2043425.html#2094219</link><dc:creator>深海沉</dc:creator><author>深海沉</author><pubDate>Thu, 12 May 2011 02:51:52 GMT</pubDate><guid>http://www.cnblogs.com/fengyishou/archive/2011/05/12/2043425.html#2094219</guid><description><![CDATA[等答案<br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/fengyishou/" target="_blank">深海沉</a> 2011-05-12 10:51 <a href="http://www.cnblogs.com/fengyishou/archive/2011/05/12/2043425.html#2094219#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Re:在ASP.NET MVC中进行排序</title><link>http://www.cnblogs.com/fengyishou/archive/2011/05/05/2028513.html#2087278</link><dc:creator>风疑</dc:creator><author>风疑</author><pubDate>Thu, 05 May 2011 06:55:05 GMT</pubDate><guid>http://www.cnblogs.com/fengyishou/archive/2011/05/05/2028513.html#2087278</guid><description><![CDATA[@根号贰
比我的代码优雅多了。<br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/fengyishou/" target="_blank">风疑</a> 2011-05-05 14:55 <a href="http://www.cnblogs.com/fengyishou/archive/2011/05/05/2028513.html#2087278#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Re:在ASP.NET MVC中进行排序</title><link>http://www.cnblogs.com/fengyishou/archive/2011/04/25/2028513.html#2079865</link><dc:creator>根号贰</dc:creator><author>根号贰</author><pubDate>Mon, 25 Apr 2011 15:07:54 GMT</pubDate><guid>http://www.cnblogs.com/fengyishou/archive/2011/04/25/2028513.html#2079865</guid><description><![CDATA[我在想，要是有100个列要排序怎么办？

试试这个：

static IOrderedQueryable&lt;T&gt; ApplyOrder&lt;T&gt;(IQueryable&lt;T&gt; source, string property, string methodName)
        {
            Type type = typeof(T);
            ParameterExpression arg = Expression.Parameter(type, &quot;a&quot;);
            PropertyInfo pi = type.GetProperty(property);
            Expression expr = Expression.Property(arg, pi);
            type = pi.PropertyType;
            Type delegateType = typeof(Func&lt;,&gt;).MakeGenericType(typeof(T), type);
            LambdaExpression lambda = Expression.Lambda(delegateType, expr, arg);
            object result = typeof(Queryable).GetMethods().Single(
            a =&gt; a.Name == methodName
            &amp;&amp; a.IsGenericMethodDefinition
            &amp;&amp; a.GetGenericArguments().Length == 2
            &amp;&amp; a.GetParameters().Length == 2).MakeGenericMethod(typeof(T), type).Invoke(null, new object[] { source, lambda });
            return (IOrderedQueryable&lt;T&gt;)result;
        }

调用方法：property对应列名，methodName：Asc,Desc<br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/fengyishou/" target="_blank">根号贰</a> 2011-04-25 23:07 <a href="http://www.cnblogs.com/fengyishou/archive/2011/04/25/2028513.html#2079865#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Re:将Excel数据导入SQL Server数据库--2</title><link>http://www.cnblogs.com/fengyishou/archive/2010/05/12/1452067.html#1822936</link><dc:creator>xiaozhi_5638</dc:creator><author>xiaozhi_5638</author><pubDate>Wed, 12 May 2010 13:37:53 GMT</pubDate><guid>http://www.cnblogs.com/fengyishou/archive/2010/05/12/1452067.html#1822936</guid><description><![CDATA[怎样将excel中多个表 sheet1$ 、sheet2$ ……读出来呢？
怕是先要读出excel中的表名称不？<br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/fengyishou/" target="_blank">xiaozhi_5638</a> 2010-05-12 21:37 <a href="http://www.cnblogs.com/fengyishou/archive/2010/05/12/1452067.html#1822936#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>
