当前位置: 首页>>代码示例>>C#>>正文


C# File.Mkdir方法代码示例

本文整理汇总了C#中File.Mkdir方法的典型用法代码示例。如果您正苦于以下问题:C# File.Mkdir方法的具体用法?C# File.Mkdir怎么用?C# File.Mkdir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在File的用法示例。


在下文中一共展示了File.Mkdir方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: doPushNote

        // actually pushes a note to sdcard, with optional subdirectory (e.g. backup)
        private static int doPushNote(Note note)
        {
            Note rnote = new Note();
            try {
                File path = new File(Tomdroid.NOTES_PATH);

                if (!path.Exists())
                    path.Mkdir();

                TLog.i(TAG, "Path {0} Exists: {1}", path, path.Exists());

                // Check a second time, if not the most likely cause is the volume doesn't exist
                if(!path.Exists()) {
                    TLog.w(TAG, "Couldn't create {0}", path);
                    return NO_SD_CARD;
                }

                path = new File(Tomdroid.NOTES_PATH + "/"+note.getGuid() + ".note");

                note.createDate = note.getLastChangeDate().Format3339(false);
                note.cursorPos = 0;
                note.width = 0;
                note.height = 0;
                note.X = -1;
                note.Y = -1;

                if (path.Exists()) { // update existing note

                    // Try reading the file first
                    string contents = "";
                    try {
                        char[] buffer = new char[0x1000];
                        contents = readFile(path,buffer);
                    } catch (IOException e) {
                        e.PrintStackTrace();
                        TLog.w(TAG, "Something went wrong trying to read the note");
                        return PARSING_FAILED;
                    }

                    try {
                        // Parsing
                        // XML
                        // Get a SAXParser from the SAXPArserFactory
                        SAXParserFactory spf = SAXParserFactory.newInstance();
                        SAXParser sp = spf.newSAXParser();

                        // Get the XMLReader of the SAXParser we created
                        XMLReader xr = sp.getXMLReader();

                        // Create a new ContentHandler, send it this note to fill and apply it to the XML-Reader
                        NoteHandler xmlHandler = new NoteHandler(rnote);
                        xr.setContentHandler(xmlHandler);

                        // Create the proper input source
                        StringReader sr = new StringReader(contents);
                        InputSource inputSource = new InputSource(sr);

                        TLog.d(TAG, "parsing note. filename: {0}", path.Name());
                        xr.parse(inputSource);

                    // TODO wrap and throw a new exception here
                    } catch (Exception e) {
                        e.PrintStackTrace();
                        if(e as TimeFormatException) TLog.e(TAG, "Problem parsing the note's date and time");
                        return PARSING_FAILED;
                    }

                    note.createDate = rnote.createDate;
                    note.cursorPos = rnote.cursorPos;
                    note.width = rnote.width;
                    note.height = rnote.height;
                    note.X = rnote.X;
                    note.Y = rnote.Y;

                    note.setTags(rnote.getTags());
                }

                string xmlOutput = note.getXmlFileString();

                path.CreateNewFile();
                FileOutputStream fOut = new FileOutputStream(path);
                OutputStreamWriter myOutWriter =
                                        new OutputStreamWriter(fOut);
                myOutWriter.Append(xmlOutput);
                myOutWriter.Close();
                fOut.Close();

            }
            catch (Exception e) {
                TLog.e(TAG, "push to sd card didn't work");
                return NOTE_PUSH_ERROR;
            }
            return NOTE_PUSHED;
        }
开发者ID:decriptor,项目名称:tomdroid,代码行数:95,代码来源:SdCardSyncService.cs

示例2: getNotesForSync

        protected override void getNotesForSync(bool push)
        {
            SetSyncProgress(0);

            this.push = push;

            // start loading local notes
            TLog.v(TAG, "Loading local notes");

            File path = new File(Tomdroid.NOTES_PATH);

            if (!path.Exists())
                path.Mkdir();

            TLog.i(TAG, "Path {0} Exists: {1}", path, path.Exists());

            // Check a second time, if not the most likely cause is the volume doesn't exist
            if(!path.Exists()) {
                TLog.w(TAG, "Couldn't create {0}", path);
                SendMessage(NO_SD_CARD);
                SetSyncProgress(100);
                return;
            }

            File[] fileList = path.ListFiles(new NotesFilter());

            if(cancelled) {
                doCancel();
                return;
            }

            // If there are no notes, just start the sync
            if (fileList == null || fileList.Length == 0) {
                TLog.i(TAG, "There are no notes in {0}", path);
                PrepareSyncableNotes(syncableNotes);
                return;
            }

            // get all remote notes for sync

            // every but the last note
            for(int i = 0; i < fileList.Length-1; i++) {
                if(cancelled) {
                    doCancel();
                    return;
                }
                // TODO better progress reporting from within the workers

                // give a filename to a thread and ask to parse it
                SyncInThread(new Worker(fileList[i], false, push));
            }

            if(cancelled) {
                doCancel();
                return;
            }

            // last task, warn it so it will know to start sync
            SyncInThread(new Worker(fileList[fileList.Length-1], true, push));
        }
开发者ID:decriptor,项目名称:tomdroid,代码行数:60,代码来源:SdCardSyncService.cs

示例3: pullNote

        // pull note used for revert
        protected override void pullNote(string guid)
        {
            // start loading local notes
            TLog.v(TAG, "pulling remote note");

            File path = new File(Tomdroid.NOTES_PATH);

            if (!path.Exists())
                path.Mkdir();

            TLog.i(TAG, "Path {0} Exists: {1}", path, path.Exists());

            // Check a second time, if not the most likely cause is the volume doesn't exist
            if(!path.Exists()) {
                TLog.w(TAG, "Couldn't create {0}", path);
                SendMessage(NO_SD_CARD);
                return;
            }

            path = new File(Tomdroid.NOTES_PATH + guid + ".note");

            SyncInThread(new Worker(path, false, false));
        }
开发者ID:decriptor,项目名称:tomdroid,代码行数:24,代码来源:SdCardSyncService.cs

示例4: TakeAPicture

		private void TakeAPicture(object sender, EventArgs eventArgs){
			File imageStorageDir = new File(global::Android.OS.Environment.GetExternalStoragePublicDirectory( global::Android.OS.Environment.DirectoryPictures), "AndroidExampleFolder");
			if (!imageStorageDir.Exists()) {
				// Create AndroidExampleFolder at sdcard
				imageStorageDir.Mkdir();
			}

			// Create camera captured image file path and name 
			File file = new File(imageStorageDir + File.Separator + "IMG_" + Utils.RandomString(10) + ".jpg");

			mCapturedImageURI = Uri.FromFile(file); 

			// Camera capture image intent
			Intent captureIntent = new Intent(global::Android.Provider.MediaStore.ActionImageCapture);

			captureIntent.PutExtra(MediaStore.ExtraOutput, mCapturedImageURI);

			StartActivityForResult(captureIntent, FILECHOOSER_RESULTCODE);
		}
开发者ID:borain89vn,项目名称:demo2,代码行数:19,代码来源:RegistryWebView.cs


注:本文中的File.Mkdir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。