Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 18-Apr-13 0:05am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try:
 
using System.IO;
FileInfo info = new FileInfo(myCompleteFilePath);
string fileNameWithoutPath = info.Name;
 
Good luck!
  Permalink  
v3
Comments
Member61 at 18-Apr-13 5:12am
   
yes...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Saranya,
 
Try this
     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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
use FileName property of the FileUpload control. try like below.
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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Here goes:
 
string fileName = @"C:\mydir\myfile.ext";
string result = System.IO.Path.GetFileName(fileName);
 
Cheers,
Edo
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Use this
 
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();
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

 string filename = fileupload.FileName;
            int index = filename.LastIndexOf("\\");
            int len = filename.Length;
            filename = filename.Substring(index+1,len-index-1);
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 18 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100