I was following this fantastic tutorial. Which showed this bit of code to talk to my windows phone application by writing/reading to a file in the isolatedstore.
object ConManServer = WP7Device.GetType().GetField("mConmanServer", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(WP7Device);
FileDeployer f = (FileDeployer)typeof(FileDeployer).GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)[0].Invoke(new object[] { ConManServer });
f.ReceiveFile(#"\Applications\Data\" + appID + #"\data\isolatedstore\Foo.txt", #"\Foo.txt");
However, I get a file access denied. Somebody commented that:
unfortunately Microsoft has removed that feature from the final
release of the CoreCon API. So it's no longer possible to transfer
files from the device in this lovely, easy manner.
I am wondering what would be the alternative to pass instructions to my Windows Phone application from a Console Application?
Maybe using the DevicePacketStream?
The Mango (v7.1) version of the SDK included the Isolated Storage Explorer Tool to make it possible to read and write files from IsolatedStorage.
See http://msdn.microsoft.com/en-us/library/hh286408(v=vs.92).aspx
Related
I know c#; have developed for windows mobile; I now have an android project with constraints that I cannot change; the most important being cannot run above API 16 due to the devices the app will be running on. These devices are already purchased. I’m aware of the age of these devices, and how old 4.1 is; hands tied.
I’ve started a new Xamarin (not forms) project for android only; compile using 8.1 Oreo; Min version 4.1, target version 8.1. I’m aware this is not ideal however doing so I’ve managed to get lots of other needed features working including camera and barcode scanner. Changing compile version down to 4.1 causes numerous errors which won’t compile.
I’m testing the device using usb-debugging on the actual device and even though it’s 4.1, the code runs and features work – camera, scanner etc.
I’m stuck trying to create a folder and then write/read a file in that folder. I’d like this folder to be accessible via windows explorer when plugged into computer.
I’ve got code like this to write a file:
string FileContents = "Text file contents";
Java.IO.File SaveFolder = new Java.IO.File(Android.OS.Environment.GetExternalStoragePublicDirectory("Documents") + Java.IO.File.Separator + "FolderName");
Boolean Success = false;
if (!SaveFolder.Exists())
{
Success = SaveFolder.Mkdirs();
}
string FName = "test.txt";
string FTogether = System.IO.Path.Combine(SaveFolder.Path, FName);
Java.IO.FileWriter fw = new Java.IO.FileWriter(FTogether);
fw.Write(FileContents);
fw.Close();
SaveFolder.Dispose();
And code like this to read the file:
Java.IO.File SaveFolder = new Java.IO.File(Android.OS.Environment.GetExternalStoragePublicDirectory("Documents") + Java.IO.File.Separator + "FolderName");
string FName = "test.txt";
string FTogether = System.IO.Path.Combine(SaveFolder.Path, FName);
StreamReader sr = new StreamReader(FTogether);
string FileContents = sr.ReadToEnd();
Debugging reveals SaveFolder’s AbsolutePath to be /storage/sdcard0/Documents/FolderName
I think this is part of the android’s internal storage which the app has access to but nothing else.
How do I get a folder which is accessible from outside the app ?
Environment.DirectoryDocuments
cannot be used because it’s null at runtime on API 16.
The path you have is actually publicly accessible so it's not specific to your application. When you connect your Android device to the computer, you should be able to go to the root folder of the device and see the Documents folder.
Don't let the /storage/sdcard0/ part in the beginning of the path confuse you. For historical reasons, Android simulates an sdcard even if there isn't one physically on the device. In reality, /storage/sdcard0/ is just a symlink to /data/media/0.
For a really good overview of Android storage, I'd recommend you read this very thorough Reddit post: Let's clear up the confusion regarding storage in Android once and for all, including adoptable storage in Marshmallow.
What you can also do is download a file explorer app (in case your phone doesn't already have one) and go to the Documents folder. You should see FolderName there.
Edit: Since you're running on such an old version of you might also suffer from the bug in the MTP protocol, which causes newly created files and folders to be invisibile when attaching the device to a computer via USB.
The fix is to call MediaScannerConnection.scanFile for each new file/folder you've created, as explained here.
I have the code to save a file in a folder in directory
string timestamp = DateTime.Now.ToString("MM-dd-yyyy.HH-mm-ss");
var file = File.Create("Owe-Data.txt" + timestamp);
var com = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase + timestamp + #"\Data" + file;
MessageBox.Show(com);
if (!Directory.Exists(com))
{
Directory.CreateDirectory(com);
}
using (var sw = new StreamWriter(com))
{
sw.WriteLine(InputData);
}
}
i Displayed COM it gives path bt i cant see the Data folder or Owe-Data file at that path
Anybody can tell why this happening, or should i save the Data folder in current directory where this prgram running? bt i dnt know how to reach that path. Any solutions ??
Working on windows phone 5, visual studio 2008 .NET framwork 2.0
As per the Exceptions section of documentation,the above exception is thrown when
ArgumentException ------- folder is not a member of System.Environment.SpecialFolder.
It means the OS where you are running this command does not have Environment.SpecialFolder.CommonApplicationData as one of the special folder.
For knowledge,
Environment.SpecialFolder.ApplicationData is the most common one. This folder holds per-user, non-temporary application-specific data, other than user documents. A common example would be a settings or configuration file.
Environment.SpecialFolder.CommonApplicationData is similar, but shared across users. You could use this to store document templates, for instance.
Environment.SpecialFolder.LocalApplicationData is a non-roaming alternative for ApplicationData. As such, you'd never store important data there. However, because it's non-roaming it is a good location for temporary files, caches, etcetera. It's typically on a local disk.
I think the problem may be that Environment.SpecialFolder.CommonApplicationData is common and shared between different users and the user with which you have logged in is not having rights to access the folder or the Visual Studio has not been started in Admin mode.
EDIT Look at link and try to add a manual registry Common AppData defined in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\
Given you are asking about a .NET Windows Phone application as per the tags
I think your problem is that a .NET Windows Phone application does not have direct access to the file system; it can only access IsolatedStorage this is by design.
I would quote a Microsoft source for this but I can't seem to find one!
EDIT
See this article from MSDN
I've been writing a Windows 8 Store App using XAML and C# and the target device is a Windows Surface tablet.
Within my application I use a SQLite database.
To create/load the database I use the following code:
DBPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "MyDatabase.sqlite");
However I'd like to store the database in the Documents folder so I tried the follow line of code to replace my line above :
DBPath = Path.Combine(Windows.Storage.KnownFolders.DocumentsLibrary.Path, "MyDatabase.sqlite");
When I try this I get the following error:
WinRT information: Access to the specified location (DocumentsLibrary) requires a capability to be declared in the manifest.
So I open Package.appxmanifest and select Documents Library under capabilities and under the declarations tab I've added a File Type Association. Then under Properties I've entered
sqlite in the Name box and .sqlite in the File type box. I've entered no other information on the Package.appxmanifest screen.
Now when I run the app I receive the following error:
Could not open database file: MyDatabase.sqlite (CannotOpen)
When I inspect Windows.Storage.KnownFolders.DocumentsLibrary.Path it equals "". I would have expected the full location path here.
Can anyone help and has anybody ever saved a SQLite database to the documents folder?
Thanks in advance.
KnownFolders.DocumentsLibrary does not have a path since it's a virtual location. Take a look at this answer for more details. This could make it impossible to open a SQLite database there, at least using the APIs available in sqlite-net library.
Also before using access to Documents library in your Windows Store app keep in mind that for publishing an app with this capability to the store you need to have a company account. With an individual account such applications will be rejected.
I want to populate a ListBox with the localized display names of all the installed Windows Store apps in a Windows 8 desktop app. I tried this:
string Apps = Interaction.Environ("ProgramFiles") + "\\WindowsApps";
foreach ( App in IO.Directory.GetDirectories(Apps)) {
XmlDocument xml = new XmlDocument();
xml.LoadXml(My.Computer.FileSystem.ReadAllText(App + "\\AppxManifest.xml"));
lbApps.Items.Add(xml.GetElementsByTagName("DisplayName")(0).InnerText);
}
But it adds up ms-resource strings and default apps that are uninstalled.
EDIT: I found that all the installed apps have their shortcuts in %LocalAppData%\Microsoft\Windows\Application Shortcuts but those shortcuts don't have the localized name and are non-functional when opened.
Instead of parsing the AppxManifest files directly, use the PackageManager class.
On MSDN, there are quite a few samples that demonstrate how to gather a variety of content about installed application packages, including the Enumerate app packages by user SID sample.
Did you try that: http://marcominerva.wordpress.com/2012/12/17/localizing-app-name-in-windows-store-apps/
If you set correctly the AppPackage Name on the AppDevCenter, your appx on the client side will return you the localized name.
I don't think that There are Windows Runtime APIs which can expose this particular information back to the app. The owner of app is responsible to providing the information to the Appx Manifest in the first place. whatever you can take a look there-[http://msdn.microsoft.com/en-us/library/Hh446622 ] hope something can be useful for you.
The code snippet below makes use of OPOS .NET to open a POS printer for printing. It works fine when executed as part of a standalone application. When executed by a Windows Service the call to GetDevice(...) always returns null.
explorer = new PosExplorer();
device_info = explorer.GetDevice(DeviceType.PosPrinter, PrinterName);
printer = (PosPrinter)explorer.CreateInstance(device_info);
printer.Open();
printer.Claim(1000);
printer.DeviceEnabled = true;
The printer happens to be an Epson TM-U220B. Is there a security issue that needs to be overcome before a service has access to POS devices? Can anyone recommend a good source of information regarding the development of Windows Services that use OPOS .NET?
Ah OPOS, it's been a while ... ;)
It sounds like security. The way to test if it is:
1. Run the service under a user account that you know works from the standalone app
2. Check the setting in the service configuration that allows it to interact with the desktop.
Your code looks good. I see the variable name PrinterName. This variable should contain the Logical Name assigned to the printer. The Logical Name assignment is a seperate step that may be overlooked. You can confirm the proper existance of the Logical Name using POSDM available from the POS for .Net SDK. The command path would be
C:\Program Files\Microsoft Point Of Service\POSDM LISTNAMES
If the device and assigned Logical Name do not appear then that would explain your current situation.