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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:39:38+00:00 2026-06-03T09:39:38+00:00

Need help to convert code from asp control to input type to fetch file

  • 0
Need help to convert code from asp control to input type to fetch file name and file bytes.
Below are the code with asp control.
ascx Page:


 <asp:FileUpload ID="fileUp" runat="server" EnableViewState="true" class="tdFileUpload" />

ascx.cs code is given below


 using (SPSite site = new SPSite(siteId))
                    {
                        using (SPWeb web = site.OpenWeb(WebId))
                        {
                            web.AllowUnsafeUpdates = true;
                            string siteurl = SPContext.Current.Web.Url;
                            SPDocumentLibrary library;
                            library = (SPDocumentLibrary)web.Lists["Project_Artifacts"]; /fetches the library list name.
                            library.EnableVersioning = true;
                            library.Update();
                            SPFolder folder = web.Folders.Add(siteurl + "/Project_Artifacts/" + drpPrj.SelectedItem.Value);//creates a folder of selected item name                                 

web.Update();//updates the web after creating the folder
folder.Files.Add(folder.Url + “/” + fileUp.FileName, fileUp.FileBytes); // I WANT TO CHANGE THIS LINE OF CODE as per my new requirement how do i get these two values in these two mentioned places
1. fileUp.FileName
2. fileUp.FileBytes

                            folder.Update();
                            web.Update();
    }
    }

The current requirement is : 
ascx page code:


   <div id="FileUpload">
                                                                <input type="file" size="24" id="fileUp"
                                                                 onchange="getElementById('FileField').value = getElementById('fileUp').value;" />
                                                                 <div id="BrowserVisible">
                                                                    <input type="text" id="FileField" name="FileField1"/>

Hope you can figure out the ascx page code difference.
ascx.cs Page code:

folder.Files.Add(folder.Url + “/” + fileUp.FileName, fileUp.FileBytes);

I want to change this line of code with the correct line of code which i am unable to do.
Please help.Thanks in advance
  • 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-06-03T09:39:40+00:00Added an answer on June 3, 2026 at 9:39 am

    Hi I got the answer for it.
    Replace

    folder.Files.Add(folder.Url + "/" + fileUp.FileName, fileUp.FileBytes);
    

    to

    string fileFieldPathValue = Request.Form["fileFieldPath"].ToString(); 
    string fileName = System.IO.Path.GetFileName(fileFieldPathValue); 
    var bytes = System.IO.File.ReadAllBytes(fileFieldPathValue); 
    folder.Files.Add(folder.Url + "/" + fileName, bytes); 
    

    For me it worked perfectly.

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

Sidebar

Related Questions

I need help from some one to convert the following line of code from
I'm retrieving image from DB using Stream. Need someone to help me to convert
I need help with translating some code from VB to C#. Public Function ToBase36(ByVal
Need to convert the following code from Ruby to C#. However I'm kind of
I need to convert the function path::combine(path1, path2). Please help me if you have
I have an HTML help system that I need to convert to SharePoint. The
Need help writing a script downloads data from google insight using c# this is
need help in error in database pivot. i have table tamed table_score like below:
Hi I need help with the syntax on this code: IF OBJECT_ID('TEMPDB..#LTS_MAP') IS NOT
I need to create a pdf file from the HTML provided from database which

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.