我有一个代码,它读取pdfpath并显示在新的popupwindow中, 这是我的代码
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);
因设备未准备好而收到错误 如何解决这个问题?
答案 0 :(得分:0)
我知道这并没有回答你的问题(因为它的当前状态,我们无法诊断问题),但你的代码却在困扰我!你的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
}