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 7009153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:49:36+00:00 2026-05-27T21:49:36+00:00

Using an asp.net fileupload string in an Server Side onClick event. ASP.Net file upload

  • 0

Using an asp.net fileupload string in an Server Side onClick event.

ASP.Net file upload control

<asp:FileUpload ID="btnFileUpload" runat="server" Width="0px" onchange="this.form.lblUploadStatus.value=GetFileName(this.value);"/>
<asp:TextBox ID="txtUploadStatus" runat="server" Width="680px"></asp:TextBox>

Javascript

<script type="text/javascript">

function GetFileName(val) {
    var i = val.lastIndexOf("\\");
    $get('<%= txtUploadStatus.ClientID %>').value = val;
    return true;
}

</script>

.net

using (SqlConnection dbConnection = new SqlConnection(CKS_app_settings.sql_conn_string_db))
        {
            try
            {
                dbConnection.Open();
                SqlCommand command = new SqlCommand(sSQL, dbConnection);
                //command.Transaction = tn;
                command.CommandText = sSQL;
                command.CommandType = CommandType.StoredProcedure;
                command.CommandTimeout = 1024;

                // Split entire file path to grab filename
                string[] split = txtUploadStatus.Text.Split(new char[] { '\\' });
                string fileName = split[06];

                command.Parameters.AddWithValue("@p_filename", fileName);
                command.Parameters.AddWithValue("@p_url", txtUrl.Text);
                command.Parameters.AddWithValue("@p_Title", txtImgTitle.Text);
                command.Parameters.AddWithValue("@p_alt_text", txtAlt.Text);
                int rowsAffected = command.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
               // throw ex;

                //If it failed for whatever reason, rollback the //transaction
                //tn.Rollback();                          
                //No need to throw because we are at a top level call and //nothing is handling exceptions
                result = ex.InnerException.Message;
            }
        }

Maybe there was a better solution but this worked for me in the end because I want to insert data into the database and using system.io to write new file to path in one click event.

  • 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-27T21:49:37+00:00Added an answer on May 27, 2026 at 9:49 pm
    HttpPostedFile file = File1.PostedFile;
    string sName = file.FileName; // Contains file name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using <input type=file id=fileUpload runat=server> to upload a file in an ASP.NET
I want to upload a file using FileUpload Control in asp.net and i'm using
I want to get the type of file uploaded using the ASP.NET FileUpload control.
I m using asp.net 2.0 without AJAX. The file path in the fileupload control
Greetings! I am using the ASP.NET FileUpload control to allow users to upload text
I am uploading a file using a simple FileUpload control named theFile (ASP.NET). I'm
i am using asp.net 2.0 in my project using file upload control , so
I am using Ajax File Upload control in ASP.NET 4 using c#. The same
I was using a File Upload functionality in ASP.NET .If the users are using
Using ASP.Net MVC on my Site.Master I have: <head runat=server> <title><asp:ContentPlaceHolder ID=TitleContent runat=server />

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.