我想写个从服务器端下载文件的代码,写了出来后发现不行,说连不到服务器。下面是我的代码,各位看看有什么问题,指点一下啊···在web.config中的:
    <connectionStrings>
        <add name="bookConnectionString" connectionString=" Server=ALC; Database=book;User ID=0700D0C8BC4B411;"
            providerName="System.Data.SqlClient" />
    </connectionStrings>前台代码(我是用GridView的)<asp:GridView ID="gvFile" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" GridLines="Vertical" AllowPaging="true" AllowSorting="true" DataKeyNames="fileisn" Width="100%">
<Columns>
                <asp:BoundField DataField="fileisn" HeaderText="fileisn" SortExpression="fileisn" ReadOnly="true" Visible="false"/>
                <asp:BoundField DataField="filename" HeaderText="文件名" SortExpression="filename" />
                <asp:BoundField DataField="filetype" HeaderText="文件类型" SortExpression="filetype" />
                <asp:BoundField DataField="filesize" HeaderText="文件大小" SortExpression="filesize" />
                <asp:BoundField DataField="creator" HeaderText="上传者" SortExpression="creator" />
                <asp:HyperLinkField Text="下载" DataNavigateUrlFields="filename" DataNavigateUrlFormatString="d:\我的文档\Visual Studio 2005\WebSites\WebSite1\新建文件夹" DataTextField="filename" HeaderText="下载" DataTextFormatString="下载" Target="_blank" />   
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:bookConnectionString %>"
            SelectCommand="SELECT [fileisn], [filename], [filetype], [filesize], [creator]  FROM [userFiles]">
        </asp:SqlDataSource>我想可能是web.config里面有问题,但我不知怎么改,大家帮帮手···

解决方案 »

  1.   

    "d:\我的文档\Visual Studio 2005\WebSites\WebSite1\新建文件夹"汗... ...
    楼主先去看看如何把文件输出给用户.http://www.xueit.com/html/2009-01/21_411_00.html
      

  2.   

    <connectionStrings> 
            <add name="bookConnectionString" connectionString=" Server=ALC; Database=book;User ID=0700D0C8BC4B411;" 
                providerName="System.Data.SqlClient" /> 
        </connectionStrings> 
    没有password?是这里的问题么
      

  3.   

    password是连接字符串中的密码
    <asp:LinkButton ID="lnkbtn_LoadAtt" Text="下载" CommandName="download" OnCommand="LinkButtonClick"  CommandArgument=' <%# Eval("Id") %>' runat="server" /> 
      protected void LinkButtonClick(object sender, CommandEventArgs e) 
            { 
                if (e.CommandName == "download") 
                { 
                    int id = Convert.ToInt32(e.CommandArgument); 
                    string FileName="",AttachmentExt="",path=""; 
                  string path = Server.MapPath("~/") + obj.URL; 
                  Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(FileName, System.Text.Encoding.GetEncoding("utf-8"))  + "." + AttachmentExt); 
      Response.ContentType = "application/octet-stream"; 
      Response.WriteFile("" + path + ""); 
        Response.End(); 
                } 
      

  4.   

    那需要password 我应该从哪里获取那个password```````
      

  5.   

    要看你的数据库有设置用户和密码不,如果没有就不用写那样
    <add name="StudentConnection" Connectionstring="Data Source=.\SQLEXPRESS;Initial Catalo=数据库的名字;Integrated Securtiy=True"/>
    连接字符串这样就可以
    如果有设置用户名密码
      <add name="MyblogsConnectionString1" connectionString="Data Source=.;Initial Catalog=Myblogs;User ID=用户名;Password=密码"/>