TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
John Riker
NA
85
15.6k
Adding string array in config file
Oct 29 2020 10:22 AM
I have an app that loops thru video files of various extensions and converts them. I had the list of extensions hard coded during testing:
string
[] extensions = {
".mp4"
,
".mov"
,
".avi"
,
".mpg"
,
".wmv"
,
".mkv"
,
".m4v"
};
That is used in my loop as:
foreach
(
string
file
in
Directory.EnumerateFiles(rootfolder,
"*.*"
, searchOption)
.Where(s => extensions.Any(ext => ext == Path.GetExtension(s))))
Works fine.
I tried adding it to my appname.config in several ways:
<xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
configuration
>
<
startup
>
<
supportedRuntime
version
=
"v4.0"
sku
=
".NETFramework,Version=v4.6.1"
/>
</
startup
>
<
appSettings
>
<
add
key
=
"extensionstest"
value
=
""
.mp4",".mov",".avi",".mpg",".wmv",".mkv",".m4v""
/>
</
appSettings
>
</configuration
>
Tried the above with ampersand quote semicolon and without any quotes so with the period and the extension name but it doesn't seem to parse it on output. It may actually do the first one but not 100% sure.
Tried retrieving it in several fashions but latest was:
string
[] extensions = ConfigurationManager.AppSettings[
"extensionstest"
].Split(
','
);
Any help with the most efficient way to do this or do I need to hard code this and recompile if new extensions come up I need to handle?
Thanks.
JR
Reply
Answers (
4
)
I want to store 200 options in list and retrieve according to use
C# algorithm Array