要求根据url参数访问数据库并下载数据库内的数据
public partial class Terrain : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String fp=@"D:\yang";
Directory.SetCurrentDirectory(fp);
int level = int.Parse(Request.QueryString["level"]);
int row = int.Parse(Request.QueryString["row"]);
int col = int.Parse(Request.QueryString["col"]);
GetTerrainTile(level, row, col);
}
private void GetTerrainTile(int level, int row, int col)
{
try
{
String cnnStr = ConfigurationManager.ConnectionStrings["GE"].ConnectionString;
using (SqlConnection cnn = new SqlConnection(cnnStr))
{
String cmdStr = @"declare @s varchar(50)
select @s=DataBaseName from Metadata_DB where ID=(select DB from Metadata_Terrain where Level='" + level + "' and Row='" + row + "' and Col='" + col + "') exec('use '+@s+' select Data from Data where Level=''" + level + "'' and Row=''" + row + "'' and Col=''" + col + "''')";
SqlCommand cmd = new SqlCommand(cmdStr, cnn);
cnn.Open();
SqlDataReader dataReader = cmd.ExecuteReader();
while (dataReader.Read())
{
Response.BinaryWrite((byte[])dataReader["Data"]);
}
//FileStream fs = new FileStream("Terrain1.bil", FileMode.Create);
//fs.Write((byte[])dataReader["Data"], 0, 10000);
//ZipOutputStream zs = new ZipOutputStream(fs);
//zs.SetLevel(9); //fs.Close();
cnn.Close();
}
Response.ClearContent();
Response.ContentType = "application/zip";
Response.AppendHeader("Content-Length", "application/x-msdownload");
Response.AppendHeader("") }
catch (SqlException e)
{
Response.Write(e.Message.ToString());
}
Response.End();
Response.Close();
}
}下面是xml文件
<?xml version="1.0"?>
<configuration>
<appSettings>
</appSettings>
<connectionStrings>
<add name="GE" connectionString="Data Source=YAOGAN-SERVER;Initial Catalog=VRMSMain;User ID=sa;Password=sa" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
</system.web>
</configuration>
错误说XML 文档必须有一个顶层元素。处理资源 'http://localhost:4519/Terrain/Terrain.aspx?level=0&row=3696&col=8429' 时出错。
代码是网上找的加自己改的,主要是不明白红字部分,大家帮忙解答下
public partial class Terrain : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String fp=@"D:\yang";
Directory.SetCurrentDirectory(fp);
int level = int.Parse(Request.QueryString["level"]);
int row = int.Parse(Request.QueryString["row"]);
int col = int.Parse(Request.QueryString["col"]);
GetTerrainTile(level, row, col);
}
private void GetTerrainTile(int level, int row, int col)
{
try
{
String cnnStr = ConfigurationManager.ConnectionStrings["GE"].ConnectionString;
using (SqlConnection cnn = new SqlConnection(cnnStr))
{
String cmdStr = @"declare @s varchar(50)
select @s=DataBaseName from Metadata_DB where ID=(select DB from Metadata_Terrain where Level='" + level + "' and Row='" + row + "' and Col='" + col + "') exec('use '+@s+' select Data from Data where Level=''" + level + "'' and Row=''" + row + "'' and Col=''" + col + "''')";
SqlCommand cmd = new SqlCommand(cmdStr, cnn);
cnn.Open();
SqlDataReader dataReader = cmd.ExecuteReader();
while (dataReader.Read())
{
Response.BinaryWrite((byte[])dataReader["Data"]);
}
//FileStream fs = new FileStream("Terrain1.bil", FileMode.Create);
//fs.Write((byte[])dataReader["Data"], 0, 10000);
//ZipOutputStream zs = new ZipOutputStream(fs);
//zs.SetLevel(9); //fs.Close();
cnn.Close();
}
Response.ClearContent();
Response.ContentType = "application/zip";
Response.AppendHeader("Content-Length", "application/x-msdownload");
Response.AppendHeader("") }
catch (SqlException e)
{
Response.Write(e.Message.ToString());
}
Response.End();
Response.Close();
}
}下面是xml文件
<?xml version="1.0"?>
<configuration>
<appSettings>
</appSettings>
<connectionStrings>
<add name="GE" connectionString="Data Source=YAOGAN-SERVER;Initial Catalog=VRMSMain;User ID=sa;Password=sa" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
</system.web>
</configuration>
错误说XML 文档必须有一个顶层元素。处理资源 'http://localhost:4519/Terrain/Terrain.aspx?level=0&row=3696&col=8429' 时出错。
代码是网上找的加自己改的,主要是不明白红字部分,大家帮忙解答下
解决方案 »
- 请问listview在绑定一个datatable后如何分页呢?
- 【警告】,广大求职者注意(特别是应届生,社会经历尚浅者)。。。
- 一个关于asp.net2.0 TreeView的SelectedNodeChanged事件问题
- Application对象问题
- URL编码
- dropdownlist的item在客户端变化为什么在服务器端不能识别?
- 复合控件其中一个显示不出来
- Table1.Rows(i).Cells(0).Controls(1)中的0和1是什么意思?
- 为什么我的calender控件,在网站发布之后就不能用了
- 如何做动态打印;最好有例子
- html Select问题-----------------------刷新后保存其状态
- css菜单的问题,请各位大虾们帮忙
Response.ContentType = "application/zip";//类型
Response.AppendHeader("Content-Length", "application/x-msdownload");//将 HTTP 头添加到输出流。
Response.AppendHeader("")
文件下载,指定默认名
Response.AddHeader(”content-type”,”application/x-msdownload”);
Response.AddHeader(”Content-Disposition”,”attachment;filename=要下载的文件名.rar”);
Response.AddHeader("Content-Disposition", "attachment;filename=" & HttpUtility.UrlEncode(“附件名称”))