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

  • Home
  • SEARCH
  • 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 7420263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:12:29+00:00 2026-05-29T08:12:29+00:00

I need help to make fileupload.cs reusable for uploading gallery images in content/gallery folder

  • 0

I need help to make fileupload.cs reusable for uploading gallery images in content/gallery folder and downloadable files in content/files folder. I believe the solution will be in making the filepaths string somehow dynamic. The gallery and File have different controllers,models and views. Below is the fileupload.cs code

public static class FileUpload

{
    public static char DirSeparator =  System.IO.Path.DirectorySeparatorChar;
    public static string FilesPath = "Content" + DirSeparator + "Files" + DirSeparator;
    public static string UploadFile(HttpPostedFileBase file)
    {
        // Check if we have a file
        if (null == file) return "";
        // Make sure the file has content
        if (!(file.ContentLength > 0)) return "";
        string fileName = file.FileName;
        string fileExt = Path.GetExtension(file.FileName);
        // Make sure we were able to determine a proper 
        // extension
        if (null == fileExt) return "";
        // Check if the directory we are saving to exists
        if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory+FilesPath))
        {
        // If it doesn't exist, create the directory
            Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory+FilesPath);
        }
        // Set our full path for saving
        string path = FilesPath + DirSeparator + fileName;
        // Save our file
        //file.SaveAs(Path.GetFullPath(path));
        file.SaveAs(Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory +path));
        // Return the filename
        return fileName;
    }
    public static void DeleteFile(string fileName)
    {
    // Don't do anything if there is no name
        if (fileName.Length == 0) return;
   // Set our full path for deleting
        string path = FilesPath + DirSeparator + fileName;
     // Check if our file exists
        if (File.Exists(Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory+path)))
        {
            // Delete our file
            File.Delete(Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory+path));
        }
    }
}
  • 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-29T08:12:30+00:00Added an answer on May 29, 2026 at 8:12 am

    You can check if uploaded file has konwn image format extension (jpg, gif, png, etc) and if so then save to your content/gallery folder otherwise save to your content/files folder.

    You are checking the file etension anyway

    string fileExt = Path.GetExtension(file.FileName);
    

    but you never use it.

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

Sidebar

Related Questions

This is beyond my level and I need some help. In the htaccess make
I am trying to make SELECT statement for following situation and need help to
i need help, i have some data coming in xml, i want to make
First of all I am in DESPERATE need of help here PLEASE I will
I need some help with make a datatable from sql. I'm a Newbie. I
i try to build a menu and i need some help to make it
I need help, I need to make a menu that only shows when you
I need help with Facebook OAuth. I am trying to make a facebook news
I need help for make a own button class and linking this with the
Need help figuring out how to do this. My code: my %hash; $hash{'1'}= {'Make'

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.