Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I need to give only filename as Parameter in that SP

connectionstring();
SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand cmd = new SqlCommand("Excel", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@ExcelName", SqlDbType.VarChar).Value = FileUpload1.ToString();
cmd.ExecuteNonQuery();
con.Close();
Posted
Updated 10-Feb-23 2:22am

Try:

using System.IO;

FileInfo info = new FileInfo(myCompleteFilePath);
string fileNameWithoutPath = info.Name;


Good luck!
 
Share this answer
 
v3
Comments
Rockstar_ 18-Apr-13 5:12am    
yes...
Saranya,

Try this
C#
if(FileUploader1.HasFile)
 {
    string filename = FileUploader1.PostedFile.FileName.ToString();
 }
   connectionstring();
   SqlConnection con = new SqlConnection(str);
   con.Open();
   SqlCommand cmd = new SqlCommand("Excel", con);
   cmd.CommandType = CommandType.StoredProcedure;
   cmd.Parameters.Add("@ExcelName", SqlDbType.VarChar).Value = filename;
   cmd.ExecuteNonQuery();
   con.Close();


Thanks,
SP
 
Share this answer
 
Hi,

use FileName property of the FileUpload control. try like below.
C#
if (FileUpload1.HasFile)
{
    connectionstring();
    SqlConnection con = new SqlConnection(str);
    con.Open();
    SqlCommand cmd = new SqlCommand("Excel", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.Add("@ExcelName", SqlDbType.VarChar).Value = FileUpload1.FileName;
    cmd.ExecuteNonQuery();
    con.Close();
}


refer FileUpload Class[^]
FileUpload.FileName Property[^]

hope it helps.
 
Share this answer
 
Here goes:

C#
string fileName = @"C:\mydir\myfile.ext";
string result = System.IO.Path.GetFileName(fileName);


Cheers,
Edo
 
Share this answer
 
Use this

C#
connectionstring();
        SqlConnection con = new SqlConnection(str);
        con.Open();
        SqlCommand cmd = new SqlCommand("Excel", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@ExcelName", SqlDbType.VarChar).Value = FileUpload1.FileName;
        cmd.ExecuteNonQuery();
        con.Close();
 
Share this answer
 
https://bluegraydaily.com/page/84/?cPage&categoryid=0&enPn=5&hsId=1757957190&imageSize=Medium&live=true&m=whole&nextPage=true&numPerPage=5&paymentType=paypal&paypalEmail=sunnyslope5211%40aol.com&productName&siteUrl=http%3A%2F%2Fwww.bluegraydaily.com&stPn=1&storeId=165950&template&userId=7499332
 
Share this answer
 
C#
string filename = fileupload.FileName;
           int index = filename.LastIndexOf("\\");
           int len = filename.Length;
           filename = filename.Substring(index+1,len-index-1);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900