Read files in Windows Phone 7 - windows-phone-7

I'm trying to open a file in Windows Phone 7, but it says it doesn't exist. Here's the code I'm trying:
IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();
bool test = file.FileExists("\\ClientBin\\clubs.xml");
And in my project I added a folder called ClientBin, and the clubs.xml is in there. The clubs.xml file properties are:
Build action: Content
Copy to Output Directory: Copy always
I'm not sure what I'm doing wrong. You can see what I have in this screenshot.
Thanks!

When you ship a file with your application, it doesn't get stored in IsolatedStorage. You need use the conventional way of opening a file that ships with the XAP -
XDocument xdoc = XDocument.Load("ClientBin/customers.xml");
var customers = from query in xdoc.Descendants("Customer")
select new Customer
{
Name = (string)query.Element("Name"),
Employees = (int)query.Element("Employees"),
Phone = (string)query.Element("Phone")
};
// Data bind to listbox
listBox1.ItemsSource = customers;
HTH, indyfromoz

Related

Google Advanced Drive API fails on insert of some PDFs but not others

function extractTextFromPDF() {
// PDF File URL
// You can also pull PDFs from Google Drive
// this Fall2019_LLFullCatalog.pdf will not insert - internal error on insert is all the feedback that gets logged"
// doesn't matter if I retrieve it from the university website or if I first copy it to my google drive and then retrieve it from there
//var url = "https://uwf.edu/media/university-of-west-florida/offices/continuing-ed/leisure-learning/docs/Fall2019_LLFullCatalog.pdf";
//var url = "https://drive.google.com/drive/u/0/my-drive/Fall2019_LLFullCatalog.pdf";
// both of these pdfs will insert just fine. Size is not the issue because this one is much larger than the one I need to insert
var url = "https://eloquentjavascript.net/Eloquent_JavaScript_small.pdf";
//var url = "https://img.labnol.org/files/Most-Useful-Websites.pdf";
var blob = UrlFetchApp.fetch(url).getBlob();
var size = blob.getBytes().length;
var resource = {
title: blob.getName(),
mimeType: blob.getContentType()
};
// Enable the Advanced Drive API Service
var file = Drive.Files.insert(resource, blob, {ocr: true, ocrLanguage: "en"});
// Extract Text from PDF file
var doc = DocumentApp.openById(file.id);
var text = doc.getBody().getText();
return text;
}
See comments in code above that describe the problem.
The PDF that I need to insert with OCR is not working - regardless of whether I retrieve it from the original site or retrieve a copy that I put on google drive. However, two other PDF urls will insert just fine and one of them is considerably larger than the one that fails.
What else could be the issue, if not size limitation?
Thanks,
Steve
It could very well be a bug in the Chrome API. Not all PDF software is created equal, check if the PDF can be read in Adobe Acrobat as a simple test.

How to get the location/filepath of a file opened in Windows programmatically?

I am working on a project that needs to extract the location of a file opened in Windows.For example if a Word document is opened, I need to programmatically determine the location of the file which was opened.
I have tried using GetWindowModuleFileName() but that only provides the location where Word is installed.
The other approaches I have already tried out are:
Using Microsoft.Office.Interop to get the path using word.ActiveDocument.FullName, but it supports only Office files and that too upto Office 2013.
Handle utility which provides all the window handles referencing a given process(PID). I need to parse the output provided by this in order to isolate the file path which could be any one handle in the list and it's a difficult task.
I was wondering if there is any alternate approach/es more direct than those which I have mentioned here.
Thank you for your time.
Edit: My program uses Java Native Access(JNA) currently to get the active windows.
Here is my code:
public synchronized Map<String, Object> getWindowDetails() {
Map<String, Object> titleProcessIdMap = new LinkedHashMap<>();
char[] buffer = new char[Constants.MAX_TITLE_LENGTH * 2];
//get active window
WinDef.HWND hwnd = User32.INSTANCE.GetForegroundWindow();
//get rectangle structure of active window
WinDef.RECT rect = new WinDef.RECT();
User32.INSTANCE.GetWindowRect(hwnd, rect);
//get active window title
User32.INSTANCE.GetWindowText(hwnd, buffer, Constants.MAX_TITLE_LENGTH);
String windowTitle = Native.toString(buffer).replaceAll("\'", "\\\'");
//get process Id of active window
IntByReference pointer = new IntByReference();
User32.INSTANCE.GetWindowThreadProcessId(hwnd, pointer);
//add data to map
titleProcessIdMap.put("title", windowTitle);
titleProcessIdMap.put("pid", String.valueOf(pointer.getValue()));
titleProcessIdMap.put("rect", rect);
return titleProcessIdMap;
}
Suppose the "active window" is a Word Document, I need a way of identifying that it is a Word document and getting the filepath/location of the opened Word document in the system.

File access permission in Swift on OSX

I'm using:
let dialog = NSOpenPanel()
to get a file URL.
I'm then reading in the contents of the text file with:
let content = try String( contentsOf: dialog.url)
This works!
I'm then trying to read in another text file in the same directory with a different extension:
let b = dialog.url?.deletingPathExtension()
// Add the new file extension
let c = b?.appendingPathExtension("TSN")
let content2 = try String( contentsOf: c)
With this I get:
"The file “FLO5.TSN” couldn’t be opened because you don’t have permission to view it."
If I try and open the .tsn file with a URL from a NSOpenPanel() dialog result it works. I need to open several data files from this same directory with different extensions. Is there a way to do this?
set off sandbox!!)
Xcode 9 and later enables sandboxing by default, which severely limits interactions with the system.
Select your target, then Capabilities and set Downloads Folder to Read/Write:
In my case, solve it's startAccessingSecurityScopedResource
Example:
let selectedFile = try result.get() // get path to file
do {
// get access to open file
if selectedFile.startAccessingSecurityScopedResource() {
let path = selectedFile.path
let data = NSData(contentsOfFile: path)
print(data) // array bytes
selectedFile.stopAccessingSecurityScopedResource()
}
} catch {
// Couldn't read the file.
print(error.localizedDescription)
}
Apple wiki about this feature https://developer.apple.com/documentation/foundation/nsurl/1417051-startaccessingsecurityscopedreso

xcode 6.2 create a new simulator path every time when run the app

I used swiftData to store information on sqlite database till today it will work fine and suddenly it created a new location of database as well as simulator location
when first time run it shows
/Users/div/Library/Developer/CoreSimulator/Devices/606D7F8E-2402-4782-ADEE-12725EDB203A/data/Containers/Data/Application/2DB733AF-2544-4256-B1E5-5E8725E51CDF/Documents/DataBase.db
second time
/Users/div/Library/Developer/CoreSimulator/Devices/606D7F8E-2402-4782-ADEE-12725EDB203A/data/Containers/Data/Application/551991FA-392A-40E9-810E-31CEFCD3069A/Documents/dataBase.db
third time
/Users/div/Library/Developer/CoreSimulator/Devices/606D7F8E-2402-4782-ADEE-12725EDB203A/data/Containers/Data/Application/03E4BE03-D6E7-47BF-A98D-A129DF09DD28/Documents/DataBase.db
i used this code
let fileManager = NSFileManager()
var Sourcepath = NSBundle.mainBundle().resourcePath?.stringByAppendingPathComponent("PhotoKeeper.db");
let docsPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0] as String
let databaseStr = "DataBase.db"
let dbPath = docsPath.stringByAppendingPathComponent(databaseStr)
println(dbPath)
if(fileManager .fileExistsAtPath(dbPath) == false) {
var error:NSError?
fileManager.copyItemAtPath(Sourcepath!, toPath: dbPath, error: &error)
println(error)
}
my problem is every time new instance of database is created i.e. if i insert 2 row and compile and run the app it will create new database with zero row
You should save only relative path of your contents (document, db, ...) cause XCode with iOS8 (I suppose) changes application folder whenever you build and run it.
For example, you have your .db file in Documents, so just save your link as "DataBase.db". Then, when you need to access to this file, get the path as:
let documentsFolder = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0] as String
let dbPath = documentsFolder.stringByAppendingPathComponent("Database.db")

how to create a photo unique filename for isolated storage

I'm adding a Astronomy Picture of The Day to my Windows Phone Astronomy app, and I want to allow users to save the displayed photo to their media library. All of the examples I found show how to do this, but all of the filenames are hard coded and overwrite files that have the existing name. So I need a way to create a unique file name. How can I adjust this example to create a unique filename?
// Create a filename for JPEG file in isolated storage.
String tempJPEG = "fl.jpg";
// Create virtual store and file stream. Check for duplicate tempJPEG files.
var store = IsolatedStorageFile.GetUserStoreForApplication();
if (store.FileExists(tempJPEG))
{
store.DeleteFile(tempJPEG);
}
IsolatedStorageFileStream fileStream = store.CreateFile(tempJPEG);
StreamResourceInfo sri = null;
Uri uri = new Uri("fl.jpg", UriKind.Relative);
sri = Application.GetResourceStream(uri);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(sri.Stream);
WriteableBitmap wb = new WriteableBitmap(bitmap);
Thanks in advance for any help.
Provided you don't expect multiple saves per second
String tempJPEG = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")+".jpg";
Or some variant of that.
Just one way.

Resources