如何使用monotouch将文件从应用程序包复制到ios中的文档目录

时间:2012-08-05 04:53:37

标签: c# objective-c xamarin.ios

我在monotouch中要求tesseract ocr。我想在c#中转换以下代码。

// Set up the tessdata path. This is included in the application bundle
// but is copied to the Documents directory on the first run.
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = ([documentPaths count] > 0) ? [documentPaths objectAtIndex:0] : nil;

NSString *dataPath = [documentPath stringByAppendingPathComponent:@"tessdata"];
NSFileManager *fileManager = [NSFileManager defaultManager];
// If the expected store doesn't exist, copy the default store.
if (![fileManager fileExistsAtPath:dataPath]) {
    // get the path to the app bundle (with the tessdata dir)
    NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
    NSString *tessdataPath = [bundlePath stringByAppendingPathComponent:@"tessdata"];
    if (tessdataPath) {
        [fileManager copyItemAtPath:tessdataPath toPath:dataPath error:NULL];
    }
}

setenv("TESSDATA_PREFIX", [[documentPath stringByAppendingString:@"/"] UTF8String], 1);

我不知道如何将上面的代码转换为c#.kindly帮助我。 提前谢谢。

1 个答案:

答案 0 :(得分:3)

要访问您可以使用的文档文件夹:

string docPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal);

要管理那里的文件,您可以使用常规的System.IO方法。比如创建文件夹/文件等