I need to show list of file from Remote Server. For this I already fetch the details of Remote server using Self Hosted Web Service. i.e. I fetch remote server file name and full path as JSON String and then show the information in TreeView [WPF]. Now I need to show the icons of these files. For this I think I Can use the icon within the client desktop application and I found 2 solution
http://www.codeproject.com/Articles/2532/Obtaining-and-managing-file-and-folder-icons-using#_rating
and
WPF's
System.Drawing.Icon.ExtractAssociatedIcon
However I love the solution from Later part but it doesn't work for given file name[i.e. file should present in system, which is not the case with me]. I try to run above code's sample, and Icon shown by it are not really very good or clean. So, Is there better way to extract/get Associated file Icon for extension in C#, WPF.
Thanks.
I search more and found the CodeProject's Article is only suggested way of extracting Icon. Though I am still experimenting it and in last 2 hours I am not able to show Icon in my Treeview though object seems filled correctly for me.
Related
I am trying to build my first ever API and I want it to read some text from a .txt file.
I wrote the code originally to have the text be stored in memory and then remove it after the HTTP Get request. I had it working properly when I would run it in Visual Studio, so I decided to deploy it to Azure. I would then make the HTTP request to add more text into the memory and then I would essentially request it back, however I wouldn't get the text I wanted back. Instead I would get my error message saying that there is nothing in the list which holds the text I want.
I then decided to have it write the text to a .txt file then receive it from that. Once again this worked on my side, but once I published the code to Azure and send a request, I get a 500 Internal Server Error.
At the end of this long story is my question since I can't seem to find any details about .txt files on an Azure Web server.
Is it possible to have my C# class's in my Models folder of my API Web app read a .txt file on an Azure server?
Is it possible to have my C# class's in my Models folder of my API Web app read a .txt file on an Azure server?
The short answer: yes.
The slightly longer answer: yes, however...
As posted in the comments reading and writing information to and from a file in a web application can go bad really fast. Think about two users trying to write at the same time, one user reading at the moment another one is writing and so on.
Now I can imagine the only thing you want to do right now is test to see if it works, so multiple users might not be on top of mind. But even a proof of concept deserves the correct approach, since you might learn something the wrong way otherwise.
Have a look at storing your information in a data store inside Azure, there are quite a few options. For this just to work, it's probably best to use something that's not too hard to set up like Table Storage. If you run into any issues trying to get this to work, open up a new question and we'll be happy to help.
500 Internal Server Error, these is general error in server side. I reproduce same problem and its working fine by using following steps.
After deploy on Azure its show 500 error.
you find actual error to enable Application Insights and go to Failures tab. You can see actual error why occurred.
Click on Error
See Error and File location.
Check File location, if file not there location then create a file on that location. Go to advance tool
Click to go link.
Select Cmd from Debug console dropdown. and click on Site->wwwroot
Create a txt file
Output : Now its working.
Using this namespace:
Microsoft.VisualBasic.FileIO;
I am copying a source folder from on our network to the user's computer using this line of code:
FileSystem.CopyDirectory(networkDir.FullName, localDir.FullName, UIOption.AllDialogs, UICancelOption.DoNothing);
This opens up that nice copy window we are all familiar with, which shows:
that my application is not hung up and is thinking.
how long the transfer will take.
Problem is that this window also shows the source and destination locations of the copy. I don't really want the user to see the IP and exact file path where the files are coming from.
I would like to avoid creating a big recursive foreach loop to make a directory copier, on top of having to provide an active UI that shows that the program is thinking. Are there any good workarounds or other solutions to achieve a directory copy without the source location being made public?
source location being made public
Do you control the source being downloaded from? If it's from a webserver you could make the whole thing ephemeral, and even use a hosts file entry to obfuscate the IP:
"Downloading from http://daves.server.honest/downloads/onetime/23i23i34248723084r/dir.zip"
Could be essentially useless to the 2nd person who tries to use the path.
Sadly if you're on a network drive rather than a webserver, your options are slightly more limited since it all has to be 'real' :/
I work for an IT company where we all carry around flash drives that have our most used programs on them.In my spare time I am hoping to create a "main menu" item that is kind of a fun and convenient way to access these files. I am working on creating this using Visual Studio 2013 and using visual C# windows forms. I have come across a snag however that I can't seem to find a workaround for. I am by no means fluent in C#, but I need to have a button on the windows form open a file without specifying what drive it comes from. I understand that I have to specify a path, but as these will be stored on the flash drives of myself and my coworkers I cannot foresee that the path will always begin with E:. Depending on what USB slot the drive is plugged into it could be N: or F: or the like. I have provided an example below:
Using what I currently know I am opening files using this line of code:
System.Diagnostics.Process.Start("C:/Users/Myname/Desktop/Asmodeus/Anti-Virus/Anti-Virus Installers/avast_free_antivirus_setup.exe");
Is there any way possible I can have the file open simply from
System.Diagnostics.Process.Start("Asmodeus/Anti-Virus/Anti-Virus Installers/avast_free_antivirus_setup.exe");
or something of that nature?
Thanks in advance.
There must have been some mis-communication when I asked my question previously. what I am looking to do is open an executable file via a button click on the windows form using a relative path. I am not able to specify the absolute path because the application will be run from a flash drive and therefore will change depending on what USB slot it is currently inserted into.
What I am hoping to accomplish is insert a line of code that will allow me to open an executable file that is located in the \bin\debug folder along with the application itself. I have a picture for clarification but apparently do not have enough reputation to post it. Thank you and sorry for the earlier confusion.
Usually you can just use Environment.GetFolderPath (MSDN) to give you what you need. It doesn't do absolutely everything, but if you need Desktop and the like, that is plenty.
Depending on the target version of .Net, the SpecialFolders exposed are not all there. It may turn out that you need more than they provide, but in your case it doesn't sound like it.
If there is more you need that is not covered in the default, check out this project. I'm sure there are others like it, but it does a little more than the default BCL version, using the API directly. It is at least something to read and learn (and translate from vb.. use an online translator, very quick). I haven't looked at it, but it seems like you are learning this c#/.net thingy, so it might be helpful
This article is about accessing Windows special folders.
These folders include your “Favorites”, “Cookies”, system libraries and the like.
Here is code, including a large number of constant definitions, plus documentation,
allowing access to and creation of these folders.
Pretty much I must find a way to populate image boxes with the corresponding information to the images, if it's possible in a Windows 8/Metro/Store App. I have a database with all the physical paths of the images which are stored on the local computer e.g: "c:\BookImages\spud.jpg". Now when i pull the information from the database with information about the book, I also take the file path of image("c:\BookImages\spud.jpg"). All i need to now do is to fetch the image and display it in a image box. But i do not how to do this, i have been researching for a while now, and I'm coming to the understanding that i cannot select file's from other than the actual install directory of the windows app. Unless i use a FileOpenPicker, which will be a useless for the user to select the folder which contains the images every time they run the app. If anyone has a solution to my problem please let me know it will be much appreciated.
See If all the directories were given access for a win rt app then it would be a security risk
So some specific folder are available try storing user data in there . After that only File Picker can Help.
Heres the link
Folders for winrt
Its a Microsoft policy so Please design app accordingly. You might needd to set capabilities in the app manifest file for some folders. Please go through it :)
The short answer is to have the user pick the folder once and save the StorageFolder in the Windows.Storage.AccessCache.
The long answer is that all this boils down to having your data store in a place that is programmatically accessible.
One option, as Anobik pointed out, is to use either your appdata folders (where you have open access), or something like the Pictures Library, which you can access given a capability in the manifest. This way you don't need to ask the user.
If you use the file picker to let the user select a folder for the data store, he or she has granted permission to access that folder programmatically, including its contained files.
The important thing is that you have to preserve that permission across sessions, which is the purpose of the AccessCache.
Think of a StorageFolder object (and a StorageFile) as an abstraction for a pathname--you never really want to save pathname strings unless you have inherent programmatic access to that location. This isn't true for stuff from the file picker, so you have to use the AccessCache to essentially save the folder reference and its permissions.
Kraig Brockschmidt
Author, Programming Windows 8 Apps with HTML, CSS, and JavaScript, a free ebook from Microsoft Press (also see second edition preview)
EDIT Solution Found: See my post below.
We are writing a library that reads in a TIF file from a scanner. Basically, its a scantron. We are examining the form and reading values from it.
Currently we have a windows test app, and we give it a filepath as a string ("c:\testing\image.tif"). It loads up the tif, reads the document correctly and parses the values.
We also have an ASP.NET web application. We have a test page that does exactly what the windows app does, we hand it an identical string, and i calls the same function on the same class from the same library. It however does NOT read the form correctly. We have verified that it does it fact load up the tif file, and it is actually filled with data (pixels we expect to be white/black are white/black when we examine the Bitmap obect in the immediate window of Visual Studio).
The specific problem is in a library called DataMatrix we use to scan a bar-code off the document. This function is supposed to return a List<string>, each of which is a barcode the library found on the document. In the windows app, this function (DataMatrixDecoder.DecodeBarcode(bitmap)) correctly returns with a Count=1. When using the asp.net app, this returns with Count=0.
Because its the exact same image file, I cannot imagine the problem is in DataMatrix. I can only assume its something with ASP.NET or something.
This isn't even my project, but another guy and I are helping our coworker figure this out, and we are just pulling our hair out. All signs indicate that ASP.NET is correctly loading and handing the image off disk to the "processor" class (which is a class library that uses the DataMatrix stuff, we are not doing ANY code in ASP.NET except for opening/handing the file to the function.).
Does anyone have any ideas as to what it might be, or different things we can check?
I'm not even sure what kind of information to give so I tried to say it all, if you have any questions please ask I'd be more than happy to elaborate on anything. Thanks.
edit:
this is the code on the ascx.cs code-behind, in a button-click event:
if (formReader.ReadTIFF(#"c:\testing\image.tif"))
{
messages.Controls.Add(HtmlHelper.DivSuccess("Read successful."));
}
The formReader class then open the file with a FileStream, and uses that to create a Bitmap. The ASP.NET application is not actually opening the file at all (we were uploading it through a FormUpload control, but after experiencing problems we dummied it down to this). This is the most perplexing thing, that it works in the windows app but not from this web site. ASP.NET has full permissions on that folder to do whatever it wants. It can open the image fine, and the bitmap it creates from the FileStream is the actual image.
edit: Also, the ReadTIFF function right now copies the FileStream into a MemoryStream, ensuring its a not a problem streaming from disk (the entire file is in memory).
How are you passing the filepath to the web application?
It is possible that the function which Decodes might be swallowing some exception.
Use reflector to examine the library (if you have not written it).
I agree. It seems your problem is most probably related to User rights on the directory where you're trying to access the files from. Try giving your Web users the Full access rights on the source directory.
EDIT
Solution Found: The problem was that the open file dialog was changing the CurrentWorkingDirectory. The reason the website never worked, was because the Environment.CurrentDirectory was set incorrectly. When I manually set the CurrentDirectory to the websites' bin folder, parsing works correctly.
Small update. Using the Windows App, and selecting the file via OpenFileDialog, will cause the barcode decoder to fail. Technically, I am using the exact same string to hand to the parser ("c:\testing\image.tif"), yet when I use the OpenFileDialog to get the string, the decoder fails. Is there a clue in this?
update: In fact, even if I don't use the string the OpenFileDialog gives me, if I just open the file dialog at all, it will fail. I don't get this. It's something simple. I need to debug the C++ DataMatrix library, really.