File not found when trying to read UWP C++
I'm trying to get a string from text file.
I create my text file by Right click on project name -> Add -> New Item...
The file Properties is set like this Excluded from Build -> No, Content -> Yes
And this is the code for reading the file.
void MyApp::MainPage::btn_readFile_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^e)
{
StorageFolder^ storageFolder = ApplicationData::Current->LocalFolder;
create_task(storageFolder->GetFileAsync("sample.txt")).then((StorageFile^ sampleFile)
{
return FileIO::ReadBufferAsync(sampleFile);
}).then((Streams::IBuffer^ buffer)
{
auto dataReader = DataReader::FromBuffer(buffer);
String^ bufferText = dataReader->ReadString(buffer->Length);
});
}
I followed this tutorial.
This is the error
Exception thrown at 0x773A1812 in WASAPI_testApp1.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x0083E280. HRESULT:0x80070002 指定されたファイルが見つかりません。
WinRT information: 指定されたファイルが見つかりません。
occurred
Sorry for the Japanese 指定されたファイルが見つかりません。mean The specified file could not be found.
uwp c++-cx
|
show 2 more comments
I'm trying to get a string from text file.
I create my text file by Right click on project name -> Add -> New Item...
The file Properties is set like this Excluded from Build -> No, Content -> Yes
And this is the code for reading the file.
void MyApp::MainPage::btn_readFile_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^e)
{
StorageFolder^ storageFolder = ApplicationData::Current->LocalFolder;
create_task(storageFolder->GetFileAsync("sample.txt")).then((StorageFile^ sampleFile)
{
return FileIO::ReadBufferAsync(sampleFile);
}).then((Streams::IBuffer^ buffer)
{
auto dataReader = DataReader::FromBuffer(buffer);
String^ bufferText = dataReader->ReadString(buffer->Length);
});
}
I followed this tutorial.
This is the error
Exception thrown at 0x773A1812 in WASAPI_testApp1.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x0083E280. HRESULT:0x80070002 指定されたファイルが見つかりません。
WinRT information: 指定されたファイルが見つかりません。
occurred
Sorry for the Japanese 指定されたファイルが見つかりません。mean The specified file could not be found.
uwp c++-cx
2
Could you add your error message into your question?
– Jesse de Bruijne
Nov 21 '18 at 8:02
So issample.txt
actually stored inApplicationData::Current->LocalFolder
? Also note that C++/CX is somewhat deprecated andC++/WinRT
should be a preferred alternative now
– VTT
Nov 21 '18 at 8:09
@VTT I'm sorry this is new to me. How do you store the file in LocalFolder? I just place it under project root folder (Same as .vcxproj) and Link it by set the Content property to Yes.
– peachy__kat
Nov 21 '18 at 8:24
I think marking item as content does nothing in case of C++ projects. So you probably need to copy this file to the desired location as a Post-Build step. Also if this file is supposed to be a part of the project then it will make sense to copy it into application folder (along with executable) instead of application data folder.
– VTT
Nov 21 '18 at 8:39
1
You can add any assets you like to an application package distributed through the Microsoft Store. You just need to make sure that the assets are indeed added to the package. The choice of programming language doesn't make a difference.
– IInspectable
Nov 22 '18 at 16:22
|
show 2 more comments
I'm trying to get a string from text file.
I create my text file by Right click on project name -> Add -> New Item...
The file Properties is set like this Excluded from Build -> No, Content -> Yes
And this is the code for reading the file.
void MyApp::MainPage::btn_readFile_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^e)
{
StorageFolder^ storageFolder = ApplicationData::Current->LocalFolder;
create_task(storageFolder->GetFileAsync("sample.txt")).then((StorageFile^ sampleFile)
{
return FileIO::ReadBufferAsync(sampleFile);
}).then((Streams::IBuffer^ buffer)
{
auto dataReader = DataReader::FromBuffer(buffer);
String^ bufferText = dataReader->ReadString(buffer->Length);
});
}
I followed this tutorial.
This is the error
Exception thrown at 0x773A1812 in WASAPI_testApp1.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x0083E280. HRESULT:0x80070002 指定されたファイルが見つかりません。
WinRT information: 指定されたファイルが見つかりません。
occurred
Sorry for the Japanese 指定されたファイルが見つかりません。mean The specified file could not be found.
uwp c++-cx
I'm trying to get a string from text file.
I create my text file by Right click on project name -> Add -> New Item...
The file Properties is set like this Excluded from Build -> No, Content -> Yes
And this is the code for reading the file.
void MyApp::MainPage::btn_readFile_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^e)
{
StorageFolder^ storageFolder = ApplicationData::Current->LocalFolder;
create_task(storageFolder->GetFileAsync("sample.txt")).then((StorageFile^ sampleFile)
{
return FileIO::ReadBufferAsync(sampleFile);
}).then((Streams::IBuffer^ buffer)
{
auto dataReader = DataReader::FromBuffer(buffer);
String^ bufferText = dataReader->ReadString(buffer->Length);
});
}
I followed this tutorial.
This is the error
Exception thrown at 0x773A1812 in WASAPI_testApp1.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x0083E280. HRESULT:0x80070002 指定されたファイルが見つかりません。
WinRT information: 指定されたファイルが見つかりません。
occurred
Sorry for the Japanese 指定されたファイルが見つかりません。mean The specified file could not be found.
uwp c++-cx
uwp c++-cx
edited Nov 21 '18 at 8:19
peachy__kat
asked Nov 21 '18 at 8:01
peachy__katpeachy__kat
265
265
2
Could you add your error message into your question?
– Jesse de Bruijne
Nov 21 '18 at 8:02
So issample.txt
actually stored inApplicationData::Current->LocalFolder
? Also note that C++/CX is somewhat deprecated andC++/WinRT
should be a preferred alternative now
– VTT
Nov 21 '18 at 8:09
@VTT I'm sorry this is new to me. How do you store the file in LocalFolder? I just place it under project root folder (Same as .vcxproj) and Link it by set the Content property to Yes.
– peachy__kat
Nov 21 '18 at 8:24
I think marking item as content does nothing in case of C++ projects. So you probably need to copy this file to the desired location as a Post-Build step. Also if this file is supposed to be a part of the project then it will make sense to copy it into application folder (along with executable) instead of application data folder.
– VTT
Nov 21 '18 at 8:39
1
You can add any assets you like to an application package distributed through the Microsoft Store. You just need to make sure that the assets are indeed added to the package. The choice of programming language doesn't make a difference.
– IInspectable
Nov 22 '18 at 16:22
|
show 2 more comments
2
Could you add your error message into your question?
– Jesse de Bruijne
Nov 21 '18 at 8:02
So issample.txt
actually stored inApplicationData::Current->LocalFolder
? Also note that C++/CX is somewhat deprecated andC++/WinRT
should be a preferred alternative now
– VTT
Nov 21 '18 at 8:09
@VTT I'm sorry this is new to me. How do you store the file in LocalFolder? I just place it under project root folder (Same as .vcxproj) and Link it by set the Content property to Yes.
– peachy__kat
Nov 21 '18 at 8:24
I think marking item as content does nothing in case of C++ projects. So you probably need to copy this file to the desired location as a Post-Build step. Also if this file is supposed to be a part of the project then it will make sense to copy it into application folder (along with executable) instead of application data folder.
– VTT
Nov 21 '18 at 8:39
1
You can add any assets you like to an application package distributed through the Microsoft Store. You just need to make sure that the assets are indeed added to the package. The choice of programming language doesn't make a difference.
– IInspectable
Nov 22 '18 at 16:22
2
2
Could you add your error message into your question?
– Jesse de Bruijne
Nov 21 '18 at 8:02
Could you add your error message into your question?
– Jesse de Bruijne
Nov 21 '18 at 8:02
So is
sample.txt
actually stored in ApplicationData::Current->LocalFolder
? Also note that C++/CX is somewhat deprecated and C++/WinRT
should be a preferred alternative now– VTT
Nov 21 '18 at 8:09
So is
sample.txt
actually stored in ApplicationData::Current->LocalFolder
? Also note that C++/CX is somewhat deprecated and C++/WinRT
should be a preferred alternative now– VTT
Nov 21 '18 at 8:09
@VTT I'm sorry this is new to me. How do you store the file in LocalFolder? I just place it under project root folder (Same as .vcxproj) and Link it by set the Content property to Yes.
– peachy__kat
Nov 21 '18 at 8:24
@VTT I'm sorry this is new to me. How do you store the file in LocalFolder? I just place it under project root folder (Same as .vcxproj) and Link it by set the Content property to Yes.
– peachy__kat
Nov 21 '18 at 8:24
I think marking item as content does nothing in case of C++ projects. So you probably need to copy this file to the desired location as a Post-Build step. Also if this file is supposed to be a part of the project then it will make sense to copy it into application folder (along with executable) instead of application data folder.
– VTT
Nov 21 '18 at 8:39
I think marking item as content does nothing in case of C++ projects. So you probably need to copy this file to the desired location as a Post-Build step. Also if this file is supposed to be a part of the project then it will make sense to copy it into application folder (along with executable) instead of application data folder.
– VTT
Nov 21 '18 at 8:39
1
1
You can add any assets you like to an application package distributed through the Microsoft Store. You just need to make sure that the assets are indeed added to the package. The choice of programming language doesn't make a difference.
– IInspectable
Nov 22 '18 at 16:22
You can add any assets you like to an application package distributed through the Microsoft Store. You just need to make sure that the assets are indeed added to the package. The choice of programming language doesn't make a difference.
– IInspectable
Nov 22 '18 at 16:22
|
show 2 more comments
1 Answer
1
active
oldest
votes
If the file is part of your project, it is not in ApplicationData::Current->LocalFolder
, it is in Package::Current->InstalledLocation
. Update your code to look there (after packaging it with your project) and it should work. Note that this location is read-only though; you can't write to your InstalledLocation
. If you want to modify the file, you will need to copy it to LocalFolder
first.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407564%2ffile-not-found-when-trying-to-read-uwp-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If the file is part of your project, it is not in ApplicationData::Current->LocalFolder
, it is in Package::Current->InstalledLocation
. Update your code to look there (after packaging it with your project) and it should work. Note that this location is read-only though; you can't write to your InstalledLocation
. If you want to modify the file, you will need to copy it to LocalFolder
first.
add a comment |
If the file is part of your project, it is not in ApplicationData::Current->LocalFolder
, it is in Package::Current->InstalledLocation
. Update your code to look there (after packaging it with your project) and it should work. Note that this location is read-only though; you can't write to your InstalledLocation
. If you want to modify the file, you will need to copy it to LocalFolder
first.
add a comment |
If the file is part of your project, it is not in ApplicationData::Current->LocalFolder
, it is in Package::Current->InstalledLocation
. Update your code to look there (after packaging it with your project) and it should work. Note that this location is read-only though; you can't write to your InstalledLocation
. If you want to modify the file, you will need to copy it to LocalFolder
first.
If the file is part of your project, it is not in ApplicationData::Current->LocalFolder
, it is in Package::Current->InstalledLocation
. Update your code to look there (after packaging it with your project) and it should work. Note that this location is read-only though; you can't write to your InstalledLocation
. If you want to modify the file, you will need to copy it to LocalFolder
first.
answered Nov 29 '18 at 4:37
Peter Torr - MSFTPeter Torr - MSFT
9,21021036
9,21021036
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407564%2ffile-not-found-when-trying-to-read-uwp-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Could you add your error message into your question?
– Jesse de Bruijne
Nov 21 '18 at 8:02
So is
sample.txt
actually stored inApplicationData::Current->LocalFolder
? Also note that C++/CX is somewhat deprecated andC++/WinRT
should be a preferred alternative now– VTT
Nov 21 '18 at 8:09
@VTT I'm sorry this is new to me. How do you store the file in LocalFolder? I just place it under project root folder (Same as .vcxproj) and Link it by set the Content property to Yes.
– peachy__kat
Nov 21 '18 at 8:24
I think marking item as content does nothing in case of C++ projects. So you probably need to copy this file to the desired location as a Post-Build step. Also if this file is supposed to be a part of the project then it will make sense to copy it into application folder (along with executable) instead of application data folder.
– VTT
Nov 21 '18 at 8:39
1
You can add any assets you like to an application package distributed through the Microsoft Store. You just need to make sure that the assets are indeed added to the package. The choice of programming language doesn't make a difference.
– IInspectable
Nov 22 '18 at 16:22