为什么实现不了上传和下载功能啊,求大神指导
    <asp:FileUpload ID="file" runat="server" />
                    </td>
                    <td>
                        <telerik:RadButton ID="but_import" runat="server" Text="上传" OnClick="but_import_Click"></telerik:RadButton>
                    </td>


                </tr>

            </table>
        </fieldset>
       </div>
      <div>
        <telerik:RadGrid runat="server" ID="grid_view" AutoGenerateColumns="false" AllowPaging="true" PageSize="15" AllowCustomPaging="true" OnNeedDataSource="grid_view_NeedDataSource" OnItemCommand="grid_ItemCommand">
            <MasterTableView DataKeyNames="filename">
                <Columns>
                    <telerik:GridBoundColumn  HeaderText="上传人" DataField="oper_name"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn HeaderText="上传时间" DataField="time"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn   HeaderText="上传文件名" DataField="filename"></telerik:GridBoundColumn>
                     <telerik:GridButtonColumn ButtonType="PushButton" HeaderText="下 载" ConfirmDialogType="RadWindow" ConfirmText="确定下载吗!?"
                            CommandName="del" Text="下 载" ConfirmTitle="提示信息" ConfirmDialogHeight="80" >
                        </telerik:GridButtonColumn>
                </Columns>
                  protected void but_import_Click(object sender, EventArgs e)
{

    //上传,添加
    try
    {
        DataTable table = this.ImportFile();
        if (table != null && table.Rows.Count > 0)
        {
            DataTable tble = this.NewTable(table);
            if (tble != null && tble.Rows.Count != 0)
            {
                Save(tble);
            }
        }
        else
        {
            Pub.Util.AlertPostBack(this.Page, "请导入Excel文件或Word文件!");
        }

    }
    catch
    {
        Pub.Util.AlertPostBack(this.Page, "导入失败!");
    }

}
private DataTable NewTable(DataTable data)
{
    DataTable table = new DataTable();
    return table;
}
private void Save(DataTable table)
{
    Pub.Util.AlertPostBack(this.Page, "导入成功");

}
private DataTable ImportFile()
{
    DataTable table = null;
    if (this.IsFile())
    {
        string temDir = Common.AppSetting.Upload_Temp_Path();
        this.file.PostedFile.SaveAs(temDir + this.file.FileName);
        table = AsposeHelper.ExcelToDataTable(temDir + this.file.FileName, true);
        System.IO.File.Delete(temDir + this.file.FileName);
    }
    return table;
}
private bool IsFile()
{
    bool isFiel = false;
    if (this.file.HasFile)
    {
        string fileName = this.file.FileName.ToLower();
        if (fileName.EndsWith("xlsx") || fileName.EndsWith("xls") || fileName.EndsWith("doc") || fileName.EndsWith("docx"))
        {
            isFiel = true;
        }
    }
    return isFiel;
}
protected void grid_view_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    DAL_ODP.DefineSql defineSql = new DAL_ODP.DefineSql();
    defineSql.AddSql("select a.oper_name,b.time,b.filename from sl_sys.t_sys_oper@dbmaizhi a inner join suxj.t_74_upload@do10 b on a.id = b.create_oper_id where a.id=" + LoginUser.ID);
    int total, pagetotal;
    grid_view.DataSource = defineSql.Query_Do10_Page(grid_view.CurrentPageIndex, grid_view.PageSize, out total, out pagetotal);
    grid_view.VirtualItemCount = total;
}
protected void grid_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    string s = e.CommandName;

    if (s == "del")
    {
        //添加记录
        string file_load = grid_view.MasterTableView.DataKeyValues[e.Item.ItemIndex]["filename"].ToString();
        DAL_ODP.DefineSql defineSql = new DAL_ODP.DefineSql();
        defineSql.AddSql("insert into  suxj.t_74_load(filename) values({0})" ,file_load);
        defineSql.ExecuteSql_Do10();
        grid_view.Rebind();
    }
}

}

net
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问