Click here to Skip to main content
11,721,289 members (85,293 online)
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 17-Apr-13 23:05pm
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 Sergey Alexandrovich Kryukov 515
1 OriginalGriff 279
2 Mika Wendelius 170
3 F-ES Sitecore 150
4 cyycoish 70
0 Sergey Alexandrovich Kryukov 2,209
1 OriginalGriff 969
2 F-ES Sitecore 660
3 Maciej Los 609
4 Richard MacCutchan 560


Advertise | Privacy | Mobile
Web03 | 2.8.150901.1 | Last Updated 18 Apr 2013
Copyright © CodeProject, 1999-2015
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