Access a local file in Silverlight - silverlight

I want to get the string from a local file (probably a Csharp file), which is attached to current project and its build action was set to Compile. Is there any way to do that. I cannot set the files' build action into Resource.
Regards,
Jawahar

I'm not clear which of these two questions you're asking:
Question 1) Can I get the text of a source file used during compilation, after compilation?
Answer 1) You'd need to set the build action to Content or Resource to do that, but realize that means you'd be shipping your source with your xap, so make sure that's what you want to do (i.e. most employers probably wouldn't like this).
You can have the file added to the xap twice by using "Add -> Existing Item -> (pick the file) -> Add As Linked Item (the little drop-down arros next to Add buton)" and set one to Compile and one to Content/Resource to accomplish this.
Question 2) Can I access a local file on the hard drive of a user of the Silverlight application?
Answer 2) Yes, by using OpenFileDialog and having the user choose the file.
Or, if you're in a Trusted Out of Browser Application (SL4 and above), then you can use the System.IO APIs to access files in My Documents, My Pictures, My Videos or My Music (on Windows an Mac) without needing to prompt the user.
Or, if you're in a Trusted OOB app, running on Windows, you can use COM and access the full file system (up to what the user can see permission-wise), again without prompt.

Related

Open file with my application

How can I handle automatically opening a file with my Windows Forms application? As in, I double-click the file and my application pops up and knows to open the file.
I'm assuming I somehow have to add an entry in the registry or something like this, and handle command line parameters, but I can't quite figure out the way to go about this.
Attached an image for clarity, it's pretty much what I want to achieve. (I'll be using my own file extension so I don't mess up other programs as well)
There's an answer in MSDN about how to associate your application with an extension. The information about shell file extension associations is stored in the registry.
Or, to set it interactively, make use of the "Open With" > "Choose default program..." feature.

Trying to find information on how to build a simple file version controll system

Im want to build a file system for non-tecks( dont care about old versions of the file so no merging or svn/git). The thougt is that a user should be able to download a file, in the same instance the file should be locked for other users. When the first user is done editing the, the file should then automaticaly upload to the server. When he closes the file, the lock should den be opend.
Is this even possible? Im thingking a sort of browser plugin, but I cant find anywone that has done the same thing. (besides microsoft, but who want to go down that road)
That would be: Sharepoint, Alfresco, (almost every WIKI), ...
Actually that is a basic feature of most document management systems. Even SVN has that already and IIRC you can set that up with mod_dav_svn without a line of code (considering configuration is not code).
Also the interesting question is, IMHO, not TheHappyCase where the described unit of work goes well but what about this*:
I Checkout 50 random documents you need
(get some popcorn and wait for your stresslevel to go up)
?????
I get bored and forget about it (everything still being checked out)
*: Points (1) and (2) may change order

How to open multiple files in explorer at the same time?

It is a little tricky to describe my question, but I'll try my best.
First, I am developing a Multi-Document-Interface app using C and WinAPI. My program is able to parse command line arguments to open multiple files. I put this string:
"X:\MyAppName.exe" "%1"
under the open with command list of the txt files so that now I can right click any .txt files in Windows Explorer and open it with my app. However, when I select multiple files, the explorer runs command "X:\MyAppName.exe" "%1" multiple times so that multiple instances of my app are started.
But wait! That's not the most tricky part. Instead, it is that my app treats opening a single file and opening multiple files at a time as two different things with seperate visual styles. I know the idea of keeping one instance running at a time (though I don't know the C code to implement it). But I don't know how to tell the difference between open several files one by one and opening multiple files at the same time.
I hope I make it clear.
Using the Registry like you currently are, you will not be able to directly differentiate between multiple files from single files. Each requested file will start a new copy of your app, as you have already noticed. If you implement single-instancing (which is not that hard to do), what you could do is detect when the first file is requested and start a short timer, then have each subsequent file reset that timer. When it finally elapses, check how many files you collected and act on them as needed.
A better, and preferred, solution is to instead create an out-of-process COM object in your app that implements the IDropTarget interface. Windows will then be able to funnel file information through a single entry point into your app. Your app will not have to care where the information is coming from. You will be able to support not only multiple files at a time, but even different formats of file information (Windows could pass you just the file names, or it could pass you the actual file data itself).
Windows will construct a single IDataObject object to hold whatever file information is needed, and will then pass it to your IDropTarget object. If your app is already running, COM will be able to access your existing IDropTarget object. If your app is not already running, COM will automatically start your app before then accessing its IDropTarget object. Either way, once it is running, your IDropTarget can look at whatever data is passed to it and decide whether to accept it or reject it.
If you register your COM object's CLSID as a DropTarget for the desired file extensions, users will be able to double-click on such files, or select such files and press Enter, and they will be passed to your IDropTarget object.
If you register an AppPath for your app and then register the CLSID as a DropTarget for it, users will be able to drag files, regardless of extension, onto your app's exe file itself, and they will be passed to your IDropTarget object.
If you use the same COM object with the RegisterDragDrop() function, users will be able to drag files, regardless of extension, onto your app's UI directly, and they will be passed to your IDropTarget object.

"Out of browser" web application running at Start-Up?

I've become familiar with the new concept of "out of browser" web applications, supported in the recent Silverlight, JavaFX, Adobe AIR etc.
Listening recently to a podcast on the subject by Scott Hanselman, I've become aware that one of the purposes behind these new architectures is to allow for "desktop-application-feel". Also, I understand some (or all) of these allow for some offline access to a sandbox of resources. This really sounds as if these frameworks could be an alternative to "real" desktop applications, as long as the application does not require messing with the user's machine (i.e. access to peripherals, certain file IO, etc).
I have a very specific question. My application needs to run at start-up. Is it possible to do so using such a framework without requiring the user to download and run a certain executable?
For example, I could always direct the user to download a small EXE that will put a .lnk file in the start-up directory, but I want to avoid such a patch.
To summarize: is it possible to have an out-of-browser web application setup itself to run at start-up without requiring file download?
To further clarify, this question does not come from an "evil" place, but rather from trying to decide whether "out-of-browser" frameworks are indeed a proper alternative to a desktop application, for my specific requirements.
The BkMark example here shows how to start an application on startup using Adobe Air. So, yes it is possible.
So, here's the deal: web apps in general will have a security context around them, and by default won't have access to write to the filesystem (outside of a temp files), access the registry, etc.
One way is, as you said, have the user run something or configure it so the lnk is executed on startup.
Another way, and I think, more in line of what you want, is that the user can run the program himself, click some button in the application, and it's configured.
I know with Java you could do this, but the user has to allow full access to their system, because your app would need to change System configuration. Then you could just configure it (by writing a lnk to your WebStart JNLP in the Startup folder)
For Internet Exploder, Javascript apps do have write access to the disk.
For other (better-secured) browsers you will either need to have a download, or Adobe AIR.
Assuming you are building for Windows, launching an executable at startup can be done several ways.
For user session startup, you can achieve this either by putting a lnk file in the appropriate folder, or with a registry entry. For operating system startup, you can achieve this with a registry entry. There are several permutations:
run application once on boot (UI not allowed)
run application every boot (UI not allowed)
start service every boot according to policy set in registry
run application once on user session start
run application every user session
Since an out of browser application has UI I expect you mean run application every user session and in this case you may as well put an LNK file in the user's startup folder.
I just created a shortcut for an SL4 OOB application, and this was the Target of the shortcut:
"C:\Program Files (x86)\Microsoft Silverlight\sllauncher.exe" 2635882436.localhost
A search of my disk revealed that location 2635882436.localhost is a folder.
C:\Users\<mylogin>\AppData\LocalLow\Microsoft\Silverlight\OutOfBrowser\2635882436.localhost
I rather doubt an OOB app of any type could place a shortcut in the Startup folder unless you somehow obtained Full Trust.

Icons from remote files

I have started coding an FTP client application (for fun). I’m trying to represent remotely hosted files with icons. For example, let’s say I’m browsing the root folder of an FTP server (/) and want to display the Backup.zip file with the icon association from that client operating system. On some systems, this may be the windows compression icon and other operating systems this may be WinZip or WinRAR icons.
I have the client browsing local files with the SHGetFileInfo() function. This works great with files that are local, however, this function requires the physical file in order to retrieve the associated icon. So, this will not work with remotely hosted files. I have found some samples of loading icons given a file extension, and this is really where the question comes in... What would be the best strategy to get icons associated to remote files?
Go to the registry every time and look up extension to icon associations
Create 1 byte files with each extension and use the SHGetFileInfo() function for remote files (using local 1 byte files as association for remote files)
Other strategies???
What would a professional software company creating an FTP client do?
Thank you for your time.
-Jessy Houle
I suggest that you don't go to the registry every time: go if you need to, but if you've already been for a given filetype then remember/cache that result (within your program) and reuse it.
Use the procedure here from a previous Stack Overflow question on the same idea and uses the registry instead of an actual file.
How can I get the filetype icon that Windows Explorer shows?

Resources