我有这段代码,它从数据库中读取数据,然后将 web.config 文件中的 url 分配给字符串。
bool isRequestCI = false;
if (context.Request.QueryString["RequestCI"] != null)
{
isRequestCI = Convert.ToBoolean(context.Request.QueryString["RequestCI"].ToString());
}
string GetFileInfo;
if (isRequestCI)
{
GetFileInfo = "select [FileName],FileExtension,MD5Hash from ElementCIBinaryAttachments where CIBinaryFileID = " + binaryFileID;
}
else
GetFileInfo = "select [FileName],FileExtension,MD5Hash from CaseFileBinaryAttachments where BinaryFileID = " + binaryFileID;
SqlCommand comGetFileInfo = new SqlCommand(GetFileInfo, cnGetFile);
SqlDataReader drFileInfo;
cnGetFile.Open();
drFileInfo = comGetFileInfo.ExecuteReader();
string fileName = "";
string fileExtension = "";
string MD5Hash = "";
while (drFileInfo.Read())
{
fileName = drFileInfo["FileName"].ToString().Trim();
fileExtension = drFileInfo["FileExtension"].ToString().Trim();
MD5Hash = drFileInfo["MD5Hash"].ToString().Trim();
}
drFileInfo.Close();
cnGetFile.Close();
string MD5PathRequestCI = ConfigurationManager.AppSettings["CIUploadedFiles"].ToString() + MD5Hash.Substring(0, 3) + @"\" + MD5Hash.Substring(3, 3) + @"\" + MD5Hash.Substring(6, 3) + @"\" + MD5Hash.Substring(9);
但是,它会导致异常string MD5PathRequestCI
说“引用未设置为对象的实例,我不知道为什么。我从来没有这样做过,或者我错过了什么?