{"id":37599,"date":"2024-11-01T09:58:51","date_gmt":"2024-11-01T09:58:51","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=37599"},"modified":"2024-11-01T11:02:04","modified_gmt":"2024-11-01T11:02:04","slug":"uwp-development-applying-local-resources","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/37599\/","title":{"rendered":"UWP Development, Applying Local Resources"},"content":{"rendered":"<p><body><\/p>\n<article>\n<p>In UWP (Universal Windows Platform) development, the ability for apps to access and utilize local resources is very important. Local resources include data provided by users to the app, and methods for effectively utilizing this data are presented. In this article, we will explain how to apply local resources in UWP apps and provide code implementations through several examples.<\/p>\n<h2>1. Understanding Local Resources<\/h2>\n<p>Local resources may include files, images, videos, audio files, etc., on the user&#8217;s device. These resources can be applied in UWP apps in various ways. Local resources can be classified into the following types:<\/p>\n<ul>\n<li><strong>File System Resources:<\/strong> Access to files stored in the user&#8217;s local storage.<\/li>\n<li><strong>Resources from Other Apps:<\/strong> For example, utilizing clipboard or data from other apps.<\/li>\n<li><strong>Settings and User Data:<\/strong> Includes app settings or user-defined data.<\/li>\n<\/ul>\n<h2>2. Setting Access to Local Resources<\/h2>\n<p>For a UWP app to access the local file system, the necessary features must be set in the app manifest. Open the <code>Package.appxmanifest<\/code> file and add the required permissions such as <code>Private Networks (Client &amp; Server)<\/code>, <code>Music Library<\/code>, <code>Pictures Library<\/code> in the <strong>Capabilities<\/strong> tab.<\/p>\n<h2>3. Accessing the File System<\/h2>\n<p>The most basic way for a UWP app to access the local file system is to use the <code>StorageFile<\/code> class. Below is an example of how to read and write files.<\/p>\n<h3>3.1. Writing a File<\/h3>\n<pre><code>\nusing Windows.Storage;\n\nasync Task WriteToFile(string content)\n{\n    StorageFolder storageFolder = ApplicationData.Current.LocalFolder;\n    StorageFile sampleFile = await storageFolder.CreateFileAsync(\"sample.txt\", CreationCollisionOption.ReplaceExisting);\n    await FileIO.WriteTextAsync(sampleFile, content);\n}\n    <\/code><\/pre>\n<p>The method above creates a <code>sample.txt<\/code> file in the application&#8217;s local folder and writes the provided content to that file.<\/p>\n<h3>3.2. Reading a File<\/h3>\n<pre><code>\nasync Task<string> ReadFromFile()\n{\n    StorageFolder storageFolder = ApplicationData.Current.LocalFolder;\n    StorageFile sampleFile = await storageFolder.GetFileAsync(\"sample.txt\");\n    string content = await FileIO.ReadTextAsync(sampleFile);\n    return content;\n}\n    <\/code><\/pre>\n<p>This method reads the contents of the <code>sample.txt<\/code> file in the local folder and returns it.<\/p>\n<h2>4. Accessing the Pictures Library<\/h2>\n<p>To access the Pictures Library in a UWP app, you need to add the <code>Pictures Library<\/code> permission. Here\u2019s an example of how to select and display images from the user&#8217;s picture library.<\/p>\n<h3>4.1. Selecting an Image<\/h3>\n<pre><code>\nasync Task<StorageFile> PickImageAsync()\n{\n    var picker = new FileOpenPicker();\n    picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;\n    picker.FileTypeFilter.Add(\".jpg\");\n    picker.FileTypeFilter.Add(\".png\");\n\n    return await picker.PickSingleFileAsync();\n}\n    <\/code><\/pre>\n<h3>4.2. Displaying the Selected Image<\/h3>\n<pre><code>\nasync void DisplayImage(StorageFile file)\n{\n    if (file != null)\n    {\n        var stream = await file.OpenAsync(FileAccessMode.Read);\n        var bitmapImage = new BitmapImage();\n        bitmapImage.SetSource(stream);\n\n        Image imageControl = new Image();\n        imageControl.Source = bitmapImage;\n\n        ContentGrid.Children.Add(imageControl); \/\/ ContentGrid is the Grid defined in XAML\n    }\n}\n    <\/code><\/pre>\n<p>This code uses a file picker to allow the user to select a photo and displays the selected image in the app&#8217;s UI.<\/p>\n<h2>5. Saving and Reading Data<\/h2>\n<p>Saving and reading data in JSON format in UWP apps is a common requirement. Below is an example of using JSON files.<\/p>\n<h3>5.1. JSON Data Model<\/h3>\n<pre><code>\npublic class UserSettings\n{\n    public string Username { get; set; }\n    public int Age { get; set; }\n}\n    <\/code><\/pre>\n<h3>5.2. Writing JSON Data<\/h3>\n<pre><code>\nasync Task SaveUserSettings(UserSettings settings)\n{\n    var json = JsonConvert.SerializeObject(settings);\n    StorageFolder storageFolder = ApplicationData.Current.LocalFolder;\n    StorageFile settingsFile = await storageFolder.CreateFileAsync(\"settings.json\", CreationCollisionOption.ReplaceExisting);\n    \n    await FileIO.WriteTextAsync(settingsFile, json);\n}\n    <\/code><\/pre>\n<h3>5.3. Reading JSON Data<\/h3>\n<pre><code>\nasync Task<UserSettings> LoadUserSettings()\n{\n    StorageFolder storageFolder = ApplicationData.Current.LocalFolder;\n    StorageFile settingsFile = await storageFolder.GetFileAsync(\"settings.json\");\n    string json = await FileIO.ReadTextAsync(settingsFile);\n\n    return JsonConvert.DeserializeObject<UserSettings>(json);\n}\n    <\/code><\/pre>\n<h2>6. Conclusion<\/h2>\n<p>This article explained how to utilize local resources in UWP development through various examples. Access to local resources is an important factor in enhancing user experience in apps, so it is essential to set the required permissions and provide a user-friendly interface. Accessing local resources is a fundamental part of UWP app development, enabling the diversity and functionality of the app.<\/p>\n<h2>7. References<\/h2>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/apps\/winui\/welcome-to-winui\">WinUI Documentation<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/apps\/develop\/file-access-permissions\">File Access Permissions Documentation<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/apps\/develop\/universal-application-platform-guide\">UWP Guide<\/a><\/li>\n<\/ul>\n<\/article>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In UWP (Universal Windows Platform) development, the ability for apps to access and utilize local resources is very important. Local resources include data provided by users to the app, and methods for effectively utilizing this data are presented. In this article, we will explain how to apply local resources in UWP apps and provide code &hellip; <a href=\"https:\/\/atmokpo.com\/w\/37599\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;UWP Development, Applying Local Resources&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[115],"tags":[],"class_list":["post-37599","post","type-post","status-publish","format-standard","hentry","category-uwp-programming"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>UWP Development, Applying Local Resources - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/37599\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"UWP Development, Applying Local Resources - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"In UWP (Universal Windows Platform) development, the ability for apps to access and utilize local resources is very important. Local resources include data provided by users to the app, and methods for effectively utilizing this data are presented. In this article, we will explain how to apply local resources in UWP apps and provide code &hellip; \ub354 \ubcf4\uae30 &quot;UWP Development, Applying Local Resources&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/37599\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:58:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:02:04+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/37599\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37599\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"UWP Development, Applying Local Resources\",\"datePublished\":\"2024-11-01T09:58:51+00:00\",\"dateModified\":\"2024-11-01T11:02:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37599\/\"},\"wordCount\":425,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"UWP Programming\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/37599\/\",\"url\":\"https:\/\/atmokpo.com\/w\/37599\/\",\"name\":\"UWP Development, Applying Local Resources - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:58:51+00:00\",\"dateModified\":\"2024-11-01T11:02:04+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37599\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/37599\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/37599\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"UWP Development, Applying Local Resources\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"UWP Development, Applying Local Resources - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/37599\/","og_locale":"ko_KR","og_type":"article","og_title":"UWP Development, Applying Local Resources - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"In UWP (Universal Windows Platform) development, the ability for apps to access and utilize local resources is very important. Local resources include data provided by users to the app, and methods for effectively utilizing this data are presented. In this article, we will explain how to apply local resources in UWP apps and provide code &hellip; \ub354 \ubcf4\uae30 \"UWP Development, Applying Local Resources\"","og_url":"https:\/\/atmokpo.com\/w\/37599\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:58:51+00:00","article_modified_time":"2024-11-01T11:02:04+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/37599\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/37599\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"UWP Development, Applying Local Resources","datePublished":"2024-11-01T09:58:51+00:00","dateModified":"2024-11-01T11:02:04+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/37599\/"},"wordCount":425,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["UWP Programming"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/37599\/","url":"https:\/\/atmokpo.com\/w\/37599\/","name":"UWP Development, Applying Local Resources - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:58:51+00:00","dateModified":"2024-11-01T11:02:04+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/37599\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/37599\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/37599\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"UWP Development, Applying Local Resources"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37599","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=37599"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37599\/revisions"}],"predecessor-version":[{"id":37600,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37599\/revisions\/37600"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=37599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=37599"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=37599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}