无法评估表达式,因为代码已优化或者本机框架位于调用stack.error之上,而pdf下载 [英] Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.error while pdf download

查看:58
本文介绍了无法评估表达式,因为代码已优化或者本机框架位于调用stack.error之上,而pdf下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,

在下载pdf文件时,出现以下错误,文件无法下载..



这里我的编码:

Dear All,
While download pdf file, following error appear and file unable to download..

Here my coding:

string strFileName = @"D:\\File\1.pdf".ToString();
                   System.IO.FileStream fs = new System.IO.FileStream(strFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                   //fs = File.Open(strFileName, FileMode.Open);
                   byte[] bytBytes = new byte[(int)fs.Length];
                   fs.Read(bytBytes, 0, (int)fs.Length);
                   fs.Close();
                   Response.AddHeader("Content-disposition", "attachment; filename=" + strFileName);
                   Response.ContentType = "application/octet-stream";
                   Response.BinaryWrite(bytBytes);
                   Response.Flush();
                   Response.End();



我使用的是Visual Studio 2008.任何命名空间都应该添加到这里?

解决我的问题..

提前致谢





问候,

Palani Kumar.A


I am using Visual studio 2008. Any namespace should add here?
Solve my issue ..
Thanks in Advance


Regards,
Palani Kumar.A

推荐答案

首先,添加命名空间不会为您做任何事情。这只是表明你不知道命名空间是什么或它用于什么。



其次,我最大的烦恼之一是看到人们打电话 .ToString()对一个字符串。来吧!!想一想!!



第三,你的文件名是无效的路径。如上所述,由于 @ 字符,您的文件名为D:\\File \1.pfd。开头附近的双反斜杠导致了问题。



我认为你不理解字面上应该处理的字符串和应该处理的字符串之间的区别对于逃脱序列。从双重对中删除一个反斜杠,它将解决问题。



最后,如果你想在响应中发送文件,你可以大大缩短此代码并删除读取文件。您根本不需要阅读它:

First, adding a namespace isn't going to do anything for you. This just shows that you have no idea what a namespace is or what it's used for.

Second, one of my greatest pet peeves is seeing people call .ToString() on a string. Come on!! Think about that!!

Third, your filename is an invalid path. As written, because of the @ character, your filename is "D:\\File\1.pfd". The double backslash near the beginning is causing a problem.

I think you're not understanding the difference between a string that should be treated literally and one that should be processed for escape sequences. Remove one of the backslashes from the doubled-up pair and it'll fix the problem.

Lastly, If you want to send a file in the response, you can shorten this code up greatly and drop reading the file. You don't need to read it at all:
string strFileName = @"D:\File\1.pdf";
Response.AppendHeader("content-disposition", "attachment; filename=" + strFileName);
Response.ContentType = "application/pdf";
Response.WriteFile(strFileName);







P.S。:匈牙利符号是什么?你知道,变量类型的前置是变量的名称??很久以前,这就是恐龙的发展方向。




P.S.: What's with the Hungarian notation?? You know, the prepending of the variable type to the name of the variable?? That went the way of the dinosaurs a long time ago.


亲爱的所有人,



谢谢大家......


我自己已经解决了我的问题..只需从我的页面中删除更新面板,它正在下载文件......



没有更新面板它会正常工作....





问候,

Palani Kumar.A
Dear All,

Thanks guys...

I have solved my issue myself.. Just remove the Update Panel from My Page, It is downloading the file...

Without Update Panel It will working fine....


Regards,
Palani Kumar.A


这篇关于无法评估表达式,因为代码已优化或者本机框架位于调用stack.error之上,而pdf下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆