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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:15:43+00:00 2026-05-14T22:15:43+00:00

I have to create an app that drills into a specific drive, reads all

  • 0

I have to create an app that drills into a specific drive, reads all file names and replaces illegal SharePoint characters with underscores.
The illegal characters I am referring to are: ~ # % & * {} / \ | : <> ? - ""

Can someone provide either a link to code or code itself on how to do this? I am VERY new to C# and need all the help i can possibly get. I have researched code on recursively drilling through a drive but i am not sure how to put the character replace and the recursive looping together. Please help!

  • 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-14T22:15:44+00:00Added an answer on May 14, 2026 at 10:15 pm

    The advice for removing illegal characters is here:

    How to remove illegal characters from path and filenames?

    You just have to change the character set to your set of characters that you want to remove.

    If you have figured out how to recurse the folders, you can get all of the files in each folder with:

    var files = System.IO.Directory.EnumerateFiles(currentPath);
    

    and then

    foreach (string file in files)
    {
        System.IO.File.Move(file, ConvertFileName(file));
    }
    

    The ConvertFileName method you will write to accept a filename as a string, and return a filename stripped of the bad characters.

    Note that, if you are using .NET 3.5, GetFiles() works too. According to MSDN:

    The EnumerateFiles and GetFiles
    methods differ as follows: When you
    use EnumerateFiles, you can start
    enumerating the collection of names
    before the whole collection is
    returned; when you use GetFiles, you
    must wait for the whole array of names
    to be returned before you can access
    the array. Therefore, when you are
    working with many files and
    directories, EnumerateFiles can be
    more efficient.


    How to recursively list directories

    string path = @"c:\dev";
    string searchPattern = "*.*";
    
    string[] dirNameArray = Directory.GetDirectories(path, searchPattern, SearchOption.AllDirectories);
    
    // Or, for better performance:
    // (but breaks if you don't have access to a sub directory; see 2nd link below)
    IEnumerable<string> dirNameEnumeration = Directory.EnumerateDirectories(path, searchPattern, SearchOption.AllDirectories);
    
    • How to: Enumerate Directories and Files
    • How to recursively list all the files in a directory in C#?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that allows you to create Home shortcuts to a specific
I have successfully created an app that reads from a bundled .plist file and
I have to create app that provides online radio streaming (icecast), preferably .ogg format.
I have a topics app that allows users to create topics. For each individual
I have written a Django app that makes use of Python threading to create
I have to create an app that will read in some info from a
Actually I have the following scenario: I want to create an app that will
I have to create a NSFetchRequest for my iPhone App that returns the same
i have a question : I want to create an app that take a
I have create an IOS app. The app has MainViewController that will present/dismiss Modal

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.