I am using asp.net fileupload control for uploading excel file from my system for exporting excel file to sql server. when i upload the file from my path, it only load filename not a full path. i need full path to execute a excel file in the sql server stored procedure.because without full path stored procedure for excel not working for me. how can solve the problem?
我正在使用asp.net fileupload控件从我的系统中上传excel文件到sql server中。当我从我的路径上上传文件时,它只加载文件名而不是完整路径。我需要完整的路径来执行sql server存储过程中的excel文件。因为如果没有完整的路径存储过程,excel就不会为我工作。如何解决这个问题?
This is my stored procedure that need full path of the excel file.so i need to get full path.
这是我的存储过程,它需要excel文件的完整路径。所以我需要得到完整的路径。
alter procedure [dbo].[sp_excelforgeneralholidays](@filname nvarchar(max),@getdate datetime,@adminid int)
as
declare @datavar nvarchar(max)
declare @sql varchar(1000)
set @datavar = 'Excel 12.0;Database=' + @filname
set nocount on
begin
set @sql ='insert into Generalholyday_details(Date,Day,Reason) SELECT * FROM OPENROWSET(''Microsoft.ACE.OLEDB.12.0'','''+@datavar+';HDR=YES'',''SELECT Date,Day,Reason FROM [Sheet1$]'')'
exec (@sql)
end
3 个解决方案
#1
0
Use This.
用这个。
string pth = Server.MapPath(FileUpload1.FileName);
#2
0
try
试一试
Server.MapPath(FileUpload1.FileName);
Hope it helps.
希望它可以帮助。
#3
0
try using this ....
试着用这....
string filename = Path.GetFileName(FileUploadControl.FileName);
FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
StatusLabel.Text = "Upload status: File uploaded!";
#1
0
Use This.
用这个。
string pth = Server.MapPath(FileUpload1.FileName);
#2
0
try
试一试
Server.MapPath(FileUpload1.FileName);
Hope it helps.
希望它可以帮助。
#3
0
try using this ....
试着用这....
string filename = Path.GetFileName(FileUploadControl.FileName);
FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
StatusLabel.Text = "Upload status: File uploaded!";