如何在提交按钮上的文件夹中上传文件在asp.net中单击c# [英] How to upload a file in folder on submit button click in asp.net c#

查看:168
本文介绍了如何在提交按钮上的文件夹中上传文件在asp.net中单击c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我正在使用Asp.net c#在Visual Studio 2008上工作。



我想在名为AttachmentsTIS的文件夹中上传PDF文件(在解决方案资源管理器中)。



附件名称文件夹是AttachementsTIS



我想通过Id使用已存在的记录上传这个pdf文件。所以我正在使用UPDATE命令。



所以我已经为此编写了代码,但它无法上传到AttachmentsTIS文件夹中。



这是我的UPDATE按钮代码。

-------



protected void btnUpdate_Click(对象发送者,ImageClickEventArgs e)

{

SqlConnection conUpdate = new SqlConnection(_connString);

SqlCommand cmdUpdate = new SqlCommand();

cmdUpdate.Connection = conUpdate;

cmdUpdate.CommandText =UPDATE AccountsInfo SET Requestor_Name ='+ TxtRequestorName.Text +',Attachment ='+ FileUploadTurnInRequest.FileName + ',''Where Id ='+ Request.QueryString [Id] +';

使用(conUpdate)

{

conUpdate.Open();

cmdUpdate.ExecuteNonQuery();

conUpdate.Close();

ScriptManager.RegisterStartupScript(this, this.GetType(),RunCode,javascript:alert('成功提交'); wi ndow.close(),document.location.href ='Home.aspx';,true);

}

}

< br $> b $ b

请帮帮我,查询一下。



谢谢。

Dear Friends,

am working on Visual studio 2008 using Asp.net c#.

I want to Upload a PDF file in folder with name AttachmentsTIS (Which is in Solution Explorer).

The Name of Attachments folder is AttachementsTIS

Just I want to upload this pdf file in already existing record by using Id. So am using UPDATE command for this.

So already i wrote code for this, but it is unable to upload in AttachmentsTIS folder.

This is my UPDATE button code.
-------

protected void btnUpdate_Click(object sender, ImageClickEventArgs e)
{
SqlConnection conUpdate = new SqlConnection(_connString);
SqlCommand cmdUpdate = new SqlCommand();
cmdUpdate.Connection = conUpdate;
cmdUpdate.CommandText = "UPDATE AccountsInfo SET Requestor_Name='" + TxtRequestorName.Text + "', Attachment='" + FileUploadTurnInRequest.FileName + "', "' Where Id = '" + Request.QueryString["Id"] + "'";
using (conUpdate)
{
conUpdate.Open();
cmdUpdate.ExecuteNonQuery();
conUpdate.Close();
ScriptManager.RegisterStartupScript(this, this.GetType(), "RunCode", "javascript:alert('Submitted Successfully');window.close(),document.location.href='Home.aspx';", true);
}
}


Please help me, check the query once.

Thanks.

推荐答案

hi



像这样使用



fileUpload.PostedFile.SaveAs (Server.MapPath(上传/+文件路径));



希望这会有所帮助
hi

use like this

fileUpload.PostedFile.SaveAs(Server.MapPath("Upload/" + filePath));

hope this will help


此代码将保存您的文件夹中的文件(pdf)

将解决方案的文件夹地址放在MapPath中
this code will save your file (pdf) in the folder
put your solution's folder address in MapPath
string savePath = MapPath("~/.../AttachmentTIS/" + ... + fileUpload.FileName);

if (fileUpload.HasFile)
{
   fileUpload.SaveAs(savePath);
}


试试这个。

使用文件上传器asp控件:



try this.
using a file uploader asp control:

private void StartUpLoad()
   {
       string fname = ".pdf";
       string chepar = TextBox1.Text + fname; //TextBox1.Text is the file name
       string pdfPath = "PDFFOLDER/" + chepar;
       string punta = "~/" + pdfPath;

   FileUpload1.SaveAs(Server.MapPath(pdfPath));


    }


这篇关于如何在提交按钮上的文件夹中上传文件在asp.net中单击c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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