Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取要文件上载的图像的路径_C#_Asp.net_Gridview - Fatal编程技术网

C# 获取要文件上载的图像的路径

C# 获取要文件上载的图像的路径,c#,asp.net,gridview,C#,Asp.net,Gridview,我需要在网格视图中获取所选图像的路径以上载文件 例如,我通过下面的代码将单元格中的选定值输入文本框 txtucname.Text = gridusers.SelectedRow.Cells[1].Text; 如何通过文件上传实现这一点 编辑任何客户记录时,如果用户未选择任何图像,则会删除以前的图像 if (imgup.HasFile) { string imgName = imgup.FileName.ToString(); imgup.SaveAs(Server.MapPa

我需要在网格视图中获取所选图像的路径以上载文件

例如,我通过下面的代码将单元格中的选定值输入文本框

 txtucname.Text = gridusers.SelectedRow.Cells[1].Text;
如何通过文件上传实现这一点

编辑任何客户记录时,如果用户未选择任何图像,则会删除以前的图像

if (imgup.HasFile)
{
    string imgName = imgup.FileName.ToString();
    imgup.SaveAs(Server.MapPath("../Images/Customer/") + imgName);
    string imgPath = "../Images/Customer/" + imgName;
    string msg = c.UpdateCustomer(txtcustid.Text, txtucname.Text, imgPath);
    msg = "<br>Image Uploaded Successfully";
    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + msg + "');", true);

}
else
{
    string msg2 = c.UpdateCustomer(txtcustid.Text, txtucname.Text,,null);
}
if(imgup.HasFile)
{
字符串imgName=imgup.FileName.ToString();
imgup.SaveAs(Server.MapPath(“../Images/Customer/”)+imgName);
字符串imgPath=“../Images/Customer/”+imgName;
字符串msg=c.UpdateCustomer(txtcustid.Text,txtcname.Text,imgPath);
msg=“
图像上传成功”; RegisterStartupScript(this.GetType(),“myalert”,“alert(“+msg+”);”,true); } 其他的 { 字符串msg2=c.UpdateCustomer(txtcustid.Text,txtcname.Text,null); }
谢谢,还有一件事,代码将被归档=unq1。hasfile或whatif(fileup.hasfile),但如果你确定会有文件名,那么直接上传到像fileup.PostedFile.SaveAs(Server.MapPath(unq1))这样的文件夹;谢谢你还有一件事,代码将被归档=unq1。hasfile或whatif(fileup.hasfile),但如果你确定会有文件名,那么直接上传到像fileup.PostedFile.SaveAs(Server.MapPath(unq1))这样的文件夹;
string Img1, unq1;
string filepath = "~/YourFolder/";
img1 = System.IO.Path.GetFileName(gridusers.SelectedRow.Cells[2].ImageName);
unq1 = filepath + img1;