c# - How to create a text File in solution Explorer? -
c# - How to create a text File in solution Explorer? -
it's bit hard explain i'll seek best. i'm not asking how create text file or read text file , display. it's more basic that.
my question is: i've written paragraph of text file don't know how set under solution explorer, programme can reference instead of writing many times.
here 1 of coding sample string , have couple of them using same text different tasks. here manually(?) wrote text(string) want save text file can refer to.
string st = "i apples. reddish apples. reddish apples greenish apples"; string result = st.orderbydescending(s => s.split(' ').count()).first(); this.lblmostwordsinsen.text = result;
actually, code above has error under split, says char doesn't contain definition split. how prepare it?
i've found coding below "text_file_name.txt" or (@"d:\test.txt") want file should not stored in d drive. should stored in programme (solution explorer?) did in web application don't know how in winform.
string filename = "alice-in-wonderland.txt"; streamreader sr = new streamreader("testfile.txt") string[] values = file.readalltext(@"d:\test.csv").split(',');
and how phone call file lastly question...
thanks in advance~
actually, code above has error under split, says char doesn't contain definition split. how prepare it?
string result = st.orderbydescending(s => s.split(' ').count()).first();
it because string st
grouping of characters. in fact
st[0],st[1],...,st[st.length-1]
when phone call st.orderbydescending
, supply lambda look s => ...
, s
not represent whole string(st
), represents elements of st
type char
, results error have mentioned above.
you can add together text file projects. , if want read them can read them this
file.readalltext("yourfilename")
but remember select file in solution explorer , right click , click properties, alter "copy output directory" property "copy always" or "copy if newer" based on situation, cause when build project, file copied in directory executable file , not need path of access it.
you can go build events tab of project properties , set actions execute when seek build project, illustration can set action re-create "yourfile" folder named "text resources" in build directory, in approach can handle more complex situation illustration when have lot of kind of resources in project.
you can read more info on build events
c# .net winforms visual-studio file-io
Comments
Post a Comment