Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1012313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:55:36+00:00 2026-05-16T09:55:36+00:00

SqlConnection conn = new SqlConnection(Data Source=DDPRO8-WIN7X86\\SQLEXPRESS;Initial Catalog=mp3bytes;Persist Security Info=True;Integrated security=true; User ID=; Password=;); SqlCommand

  • 0
    SqlConnection conn = new SqlConnection("Data Source=DDPRO8-WIN7X86\\SQLEXPRESS;Initial Catalog=mp3bytes;Persist Security Info=True;Integrated security=true; User ID=; Password=;");
    SqlCommand cmd = null;
    SqlParameter param = null;
    cmd = new SqlCommand(" INSERT INTO mp3_bytes (songs) " + " Values (@songs) ", conn);
    FileStream fs = null;

    string path = fileUpload.FileName;
    fs = new FileStream(path, FileMode.Open, FileAccess.Read);

    Byte[] song = new Byte[fs.Length];
    fs.Read(song, 0, song.Length);
    fs.Close();
    param = new SqlParameter("@songs", SqlDbType.VarBinary, song.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, song);
    cmd.Parameters.Add(param);
    conn.Open();
    cmd.ExecuteNonQuery();
    conn.Close();

where fileUpload is the file upload control. I am uploading an mp3 file.
When I execute this I’m getting could not find file ”, how can I pass the uploaded filename to filestream from upload file control?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T09:55:37+00:00Added an answer on May 16, 2026 at 9:55 am

    Use fileUpload.PostedFile.FileName

    Also its better to check if there is any file that has been uploaded using fileUpload.HasFile property. You can also guard against zero length files by checking against fileUpload.PostedFile.ContentLength > 0.

    Edit: just realized your mistake

    The uploaded file content needs to saved by you on the disk using fileUpload.PostedFile.SaveAs method. The above file name property will give you file name on the client machine, but the file will not exist on the server. You need to save it wherever you want on server. For example,

    var path = Path.Combine(tempDirectory, fileUpload.PostedFile.FileNam);
    fileUpload.PostedFile.SaveAs(path);
    

    This would put the uploaded file in the temp directory on the server. You can also use PostedFile.InputStream to read file contents.

    fs = new FileStream(path, FileMode.Open, FileAccess.Read); will never work as file does not exist on web server machine.

    Edit: based on your sample code

    Remove FileStream fs = null; and replace

    fs = new FileStream(path, FileMode.Open, FileAccess.Read);
    

    with

    var fs = uploadFile.PostedFile.InputStream;
    

    and that should do the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

System.Data.SqlClient.SqlConnection conec = new System.Data.SqlClient.SqlConnection(data source= + servidor + ; initial catalog= + basedatos
SERVER A: public string connStr = Data Source=PH-09-5336;Initial Catalog=InventoryDB;Integrated Security=True; SERVER B: public string
In this section I get the error SqlConnection conn = new SqlConnection(@Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User
string connection = Data Source= + server + ;Initial Catalog= + dbase + ;User
I have this code and need to complete it.. string conn_str = @Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\mydb.mdf;
My code: SqlConnection conn = new SqlConnection(DataSource=a;InitialCatalog=b;User ID=c;Password=d); And I get error: Keyword not
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[erp].ConnectionString); con.Open(); string intero = Select * from judete; SqlCommand
I am new in asp.net and working on the data grid view in asp.net.i
my code is as follows DataSet ds = new DataSet(); string connStr = Data
It's easy to bind a data source to something like a gridview or repeater,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.