开发者

how to get the full path of file upload control in asp.net?

i am using asp.net 2.0 in my project using file upload control , so browse the drive and select the file like path(D:\user doc new 2011\Montana\MT_SUTA_2010-2011.html) but in my code seeing error is could not find the file path is (D:\Paymycheck\OnlineTaxUserDocumentation-1\TaxesDocument\MT_SUTA_2010-2011.html) actually it is application path and take the filename only my code is

if (FileUpload.HasFile)
        {
string filepath = Server.MapPath(FileUpload.FileName);
string strHTML = File.ReadAllText(filepath);
                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                byte[] file1 = encoding.GetBytes(strHTML);
                int len = file1.Length;
                byte[] file = new byte[len]; 

                docs.TaxAuthorityName = ddlTaxAuthority.SelectedItem.Text;
                docs.TaxTypeID = ddlTaxType.SelectedValue;
                docs.TaxTypeDesc = ddlTaxType.SelectedItem.Text;
                docs.EffectiveDate = Convert.ToDateTime(txtEffectiveDate.Text);

                docs.FileName = f1;
                if (ddlTaxAuthority.SelectedValue == "FD")
                {

                    docs.Add(strHTML, file1);
                }
}

error occoured in this line

string strHTML = File.ReadAllText(filepath);

i can try like this also

string FolderToSearch = System.IO.Directory.GetParent(FileUpload.PostedFile.FileName).ToString();
string f = Path.GetDirectoryName(FileUpload.PostedFile.FileName);
string f1 = FileUpload.FileName;
                 string filepath = System.IO.Path.GetFullPath(FileUpload.PostedFile.FileName);
 string strFilePath = FileUpload.PostedFile.FileName;
string file1234 = System开发者_Go百科.IO.Path.GetFullPath(FileUpload.PostedFile.FileName);
string filepath = FileUpload.PostedFile.FileName;

so how to get the total path drive to file pls help me any one

thank u hemanth


Because your are using Server.MapPath, which according to MSDN "maps the specified relative or virtual path to the corresponding physical directory on the server." You have to first call FileUpload.SaveAs method to save file on server then try to read it's content.


If you want the total client side drive path like D:\user doc new 2011\Montana\MT_SUTA_2010-2011.html for the file MT_SUTA_2010-2011.html to be uploaded via fileupload control, then try using System.IO.Path.GetFullPath(FileUpload1.PostedFile.FileName).

This will surely return the client side path of the file.


Try this it will work

string filepath = System.IO.Path.GetFullPath(fuldExcel.PostedFile.FileName);
fuldExcel.SaveAs(filepath); //fuldExcel---is my fileupload control ID
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜