如何使用C#在ASP.Net中上载文件并将其保存到服务器 [英] how to Uploading Files in ASP.Net Using C# and Saving to the Server

查看:357
本文介绍了如何使用C#在ASP.Net中上载文件并将其保存到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用C#在ASP.Net中上载文件并将其保存到服务器.我需要样本
code

how to Uploading Files in ASP.Net Using C# and Saving to the Server.i need sample
code

推荐答案

请参见
使用ASP.NET上传文件 [ http://www.asp.net/data-access/tutorials/uploading-files-vb [^ ]
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.saveas.aspx [
See
File Upload with ASP.NET[^]
http://www.asp.net/data-access/tutorials/uploading-files-vb[^]
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.saveas.aspx[^]


获得文件上传控制权后.
在提交buttonclick事件
上使用此代码
After taking FileUpload Control .
Use this code on submit buttonclick event
protected void btnSub_Click(object sender, EventArgs e)
    {
        string filename = FileUpload1.FileName;
        FileUpload1.PostedFile.SaveAs(Server.MapPath("~\\Uploads\\" + filename));
        string path = "~\\Uploads\\" + filename;
        SqlConnection con = new SqlConnection(str);
        lblinfo.Text = "";
        lblinfo.Text = " uploaded successfully ";
        cmd = new SqlCommand("Insert into competion(headline,publication,edition,date,url) values(@head,@publication,@edition,@date,'" + path + "')", con);
        cmd.Parameters.AddWithValue("head", TextBox5.Text);
        cmd.Parameters.AddWithValue("publication", TextBox2.Text);
        cmd.Parameters.AddWithValue("edition", TextBox3.Text);
        cmd.Parameters.AddWithValue("date", TextBox4.Text);
        cmd.CommandType = CommandType.Text;
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();

    }


这篇关于如何使用C#在ASP.Net中上载文件并将其保存到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆