repeater 最后一列是下载操作列 点击下载下载服务器路径的文件
我的问题来了 我的文件编号是GUID类型的
我调试的时候发现GUID编号的值跟插入到数据库的值不一样了
怎么解决我看了下 应该是这样 我上传文件的时候 往数据库添加信息 这个时候GUID被实例化了一次 是一个值然后下载又被实例化了一次 这是第2次 所以不一样
但是不实例化怎么得到这个值来转换成sting 看代码try
{
Model.File mf = new Model.File();
BLL.NRBLL bn = new NRBLL();
Guid guid = Guid.NewGuid();
mf.Fileid = guid;
string fileid = guid.ToString();
if (bn.FN_SerchResPath(mf) != null)
{
FileInfo fileInfo = new FileInfo(bn.FN_SerchResPath(mf).Tables["t_file"].Rows[0]["FilePath"].ToString());
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=" + Server.UrlEncode(fileInfo.Name.ToString()));
Response.AddHeader("content-length", fileInfo.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = Encoding.Default;
Response.WriteFile(bn.FN_SerchResPath(mf).Tables["t_file"].Rows[0]["FilePath"].ToString());
}
else
{
Response.Write("<scirpt>alert('对不起没有数据!')</scirpt>");
}
}
catch (Exception)
{ throw;
}
我的问题来了 我的文件编号是GUID类型的
我调试的时候发现GUID编号的值跟插入到数据库的值不一样了
怎么解决我看了下 应该是这样 我上传文件的时候 往数据库添加信息 这个时候GUID被实例化了一次 是一个值然后下载又被实例化了一次 这是第2次 所以不一样
但是不实例化怎么得到这个值来转换成sting 看代码try
{
Model.File mf = new Model.File();
BLL.NRBLL bn = new NRBLL();
Guid guid = Guid.NewGuid();
mf.Fileid = guid;
string fileid = guid.ToString();
if (bn.FN_SerchResPath(mf) != null)
{
FileInfo fileInfo = new FileInfo(bn.FN_SerchResPath(mf).Tables["t_file"].Rows[0]["FilePath"].ToString());
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=" + Server.UrlEncode(fileInfo.Name.ToString()));
Response.AddHeader("content-length", fileInfo.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = Encoding.Default;
Response.WriteFile(bn.FN_SerchResPath(mf).Tables["t_file"].Rows[0]["FilePath"].ToString());
}
else
{
Response.Write("<scirpt>alert('对不起没有数据!')</scirpt>");
}
}
catch (Exception)
{ throw;
}
哦对 可是那个Guid类型的字段如何转换成string?
string转换为guid的时候 可以直接 new guid(string)的
string str = d.ToString();
这样就行了 如果是string类型的转化为Guid的 如下:
string str2 = string.Empty;
Guid g = new Guid();
g = new Guid(str2);//这样才是类型转化
g = Guid.NewGuid();//这个的意思重新生成一个Guid类型的值