I want to load all filenames from a folder in my project to a string array.
But I am not able to. Already tried it with the DirectoryInfo, but I am not able to load the wanted Directory.
Just to be sure. I do not want to copy all files to the IsolatedStorage. I just want to get the filenames.
Could anybody please provide me a solution to do it.
Thanks so far!
WP7 application does not have any API to work with file system.
If you have files in project folder - you can mark them as Resources, and read them usin
Application.GetResourceStream(new Uri(fileName, UriKind.Relative));
If files are marked as Content - you can not get the list of them. You can use only hardcoded names.
If files marked as Embedded Resources you can list them by this code:
var list = Assembly.GetCallingAssembly().GetManifestResourceNames();
Related
Just a question, I'am using c# mvc for a project and I have this requirement of getting several text files from a particular path (network path to be precised - eg: \10.0.0.1\SharedFolder). Now, each text files has different text formats and what I have to do is to get any existing files from that path folder and create a single text file for all the text files.
Is it possible to used a network path (the path was specified through user input) using a web application to access files?
If yes, what would you suggest?
I was already looking at the option of using "Browse Folder" button, however, I wasn't getting any progress on how to achieve this.
Thanks in advance.
This is how I would do it =>
Iterate through each file in the directory using the .net Directory class.
For each file:
Use the Textreaderclass to read each line
Use the Textwriter class to write each line to your designated file
Let me know if you still can't figure it out!
Yeah you can,
using (TextWriter writer = File.CreateText("C:\\Output.txt"))
{
//WRITE WHATEVER YOU WANT TO WRITE.
}
Just replace "C:\Output.txt" with the directory you want.
Hope this helps
My C# application downloads a .zip that contains at least a .dcm file.
After decompression I get something like:
download/XXXX/YYYYYY/ZZZZZZ/file.dcm
I don't know the name of these intermediary X,Y,Z folders, and I don't know how many of them exist, but I'm certain that at least a single .dcm file exists at the end of the path.
How can I get the full path of folders between download and the folder with .dcm files? (assume Windows filesystem and .Net Framework 4.0).
This will give you a list of all the files contained within the download file that would match your filename:
Directory.GetFiles("C:\\path_to_download_folder", "file.dcm", SearchOption.AllDirectories);
You could then parse the returned filepaths for whatever parts you needed. The System.IO.Path methods will probably give you want you need instead of rolling your own.
Additionally, if your application might be downloading multiple files throughout the day, and you always need to retrieve the path of the very latest matching file, you could send the filepath to a System.IO.FileInfo, which lets you get the creation time of the file, which you could use to determine which file is the newest.
I just started on my second Windows Phone application, and I ran into a problem (ehm..challange). In my app, I have added a folder called "Images", and some sub-folders, like this:
Images -> boys -> graphs
The boys folder contains 1 xml file, and the graphs folder contains hundreds of .gif images. And I'm now wondering how to access these files, how can I build them into the .xap file, what's the recommended way to go?
Should I set the files to "Content" or "Resource", "Copy to output folder"?
And how do I refer to these files, both the xml file in "boys", and the gif images in "graphs"?
A bit confused, and hoping that there is someone who can kick me in the right direction :)
edit, more info
I got it working, loading the xml file with the code below, I haven't tried with the images yet, but is this "the way to do it"?
string xmlBoys = #"images/boys/Names.xml";
Uri uri = new Uri(xmlBoys, UriKind.Relative);
StreamResourceInfo sm = Application.GetResourceStream(uri);
System.Xml.XmlReader xr = System.Xml.XmlReader.Create(sm.Stream);
XDocument data = XDocument.Load(xr);
If you set the BuildAction on the images to Content you can refer to them by the relative path.
e.g.: new Uri("\Images\boys\graphs\img1.gif", UriKind.Relative);
You don't need to "Copy to output folder" unless you need them there for your own purposes. You probably don't. That option is an artefact of other types of project. Everythign you need to distribute will be bundled in the XAP.
Importantly, however, note that WP7 does not have native support for gif format files. I'd suggest converting these to PNG before trying to use them.
My application need to download multiple files in Silverlight, and because I don't want to ask user multiple times for permission to save the files, I save the files in IsolatedStorage first and then I want to zip them all to a file and ask once for saving permission.
therefore I used SharpZipLib to zip multiple files which are located in IsolatedStorage, the problem is that SharpZipLib just accept file address as ZipEntery:
ZipEntry z= new ZipEntry(name);
and as you know cause the files are located in IsolatedStorage I don't have the address of them.
I saw sample on Create a Zip from/to a memory stream or byte array but I cant use it for multiple files.
Please help me to find a way to use SharpZipLib or introduce me another way to downloading multiple files without asking multiple times for permission.
The name in ZipEntry z= new ZipEntry(name); is a logical/relative name inside your zip, you can establish it any way you want.
So as long as you can re-open you IsoStorage files as a Stream, you should be able to use SharpZip.
I have a very huge amount of images (about 20K) that I don't want to be directly accessible by a user. Therefore I have a controller that streams a requested images back if the requesttoken is valid. I wonder now if I should store the images within a internal Resourcefile or just as content? I tried content before but you are able to access them from the browser if you know the folder and filename. The files don't change at runtime.
Thanks in advance for any hint on this!
You should use the App_Data folder for this. This folder is hidden from the outside so it is ideal for storing embedded databases or files as you want.
You may be interested in:
What is the App_Data folder used for in Visual Studio?