我如何使用c#.net代码从FileUpload控制器获取文件的完整路径 [英] how can i get full path of file from FileUpload controler using c#.net code
问题描述
hi 全部
我需要将xls文件数据从客户端上传到服务器端sql Server
table,因为我在asp.net控件中使用了FileUpload控件,但是我没有得到
客户端提供文件的完整路径,我该怎么办?您能帮我一个忙吗
而且我不需要将该文件保存到服务器端
我使用了以下代码,但仍然只能获取文件名,而不能获取完整路径
请帮助我
hi All
i need to upload xls file data from client side to server side sql Server
table , for that i used FileUpload control in asp.net controls, but i am not geting
file full path from client side how can i get can you please help me any one
and i need not to save that file to server side
i used these following code but still i am getting file name only but not full path
please help me
string FileName = FileUpload1.FileName;
string fillPath = FileUpload1.PostedFile.FileName;
以下代码我也尝试过,但是它可以节省服务器端,但是我不需要保存
从服务器端,只需要使用C#.net代码从客户端计算机获取路径
the following code also i tried but it is saving server side but i dont need to save
from server side , just i need only Path from Client Computer using C#.net Code
FileUpload1.SaveAs(Server.MapPath("download/" + "NewExcel.xlsx"));
谢谢
Sudheer.N
Thanks
Sudheer.N
推荐答案
string filename = FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath("~\\Uploadform\\" + filename.Trim()));
string path = "~\\Uploadform\\" + filename.Trim();
SqlConnection con = new SqlConnection(str);
cmd = new SqlCommand("Insert into Circular(date,ctype,title,type,url1) values('"+txtdate.Text+"','" + TextBox1.Text + "','" + txttitle.Text + "','" + txttype.Text + "','" + path + "' )", con);
lblinfo.Text = " Uploaded Successfully ";
cmd.CommandType = CommandType.Text;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
这篇关于我如何使用c#.net代码从FileUpload控制器获取文件的完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!