我有一个代码,它读取pdfpath并显示在新的pop逆风窗口中,这是我的代码
string path = Request.QueryString["val"].ToString();
string extention = Path.GetExtension(path);
int len = extention.Length - 1;
string extwithoutdot = extention.Substring(1, len);
if (extwithoutdot.Equals("JPG") ||
extwithoutdot.Equals("jpg") ||
extwithoutdot.Equals("jpeg") ||
extwithoutdot.Equals("JPEG"))
{
extwithoutdot = "jpeg";
}
if (extwithoutdot.Equals("TIF") || extwithoutdot.Equals("tif"))
{
extwithoutdot = "tiff";
}
if (extwithoutdot.Equals("GIF") || extwithoutdot.Equals("gif"))
{
extwithoutdot = "gif";
}
if (extwithoutdot.Equals("BMP") || extwithoutdot.Equals("bmp"))
{
extwithoutdot = "bmp";
}
string filetype = "";
if (extention.Equals(".pdf") || extention.Equals(".PDF"))
{
extwithoutdot = "pdf";
filetype = "PDF";
}
WebClient client = new WebClient();
//driveInfo.IsReady;
Byte[] buffer = client.DownloadData(path);
由于设备未就绪,我收到错误如何解决这个问题?
我知道这不能回答你的问题(因为在它的当前状态下,我们不可能诊断出问题),但你的代码正在困扰我!你的if
语句效率非常低,可以用一个漂亮的switch
块重写:
//First make the string lowercase:
string extwithoutdot = extention.Substring(1, len).ToLower();
switch(extwithoutdot)
{
case "jpg":
extwithoutdot = "jpeg";
break;
case "tif":
extwithoutdot = "tiff";
break;
default:
//Don't need to do anything
}