7 Replies - 9927 Views - Last Post: 21 September 2012 - 07:58 AM

#1 babbu25  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 68
  • Joined: 26-November 11

How to Include a File to read values in Windows Mobile Application

Posted 25 March 2012 - 08:17 AM

Hi friends

I am working in Visual studio 2008 using C#.In my Mobile application i wanted to check the value entered in the text box with the values in the FILE.But i am not able to find the path when i Run with the EMulator.

Here is the simple code i used
private void btnPswdSbmit_Click(object sender, EventArgs e)
        {
            string Filepath = "Project.txt";
            if (File.Exists(Filepath) == true)
            {             

                line = strread.ReadLine();
                if (line == txtPswd.Text)
                {
                    Basic b = new Basic();
                    b.Show();
                    this.Close();

                }

            }





Can any one guide me why my File is not found by the emulator compiler.I have seen online and searched a lot They gave me different solutions but the problem was that even i couldnt load

System.IO.IsolatedSTorage.

Any other way to load my file??

Thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: How to Include a File to read values in Windows Mobile Application

#2 TheObserver  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 12-March 12

Re: How to Include a File to read values in Windows Mobile Application

Posted 25 March 2012 - 01:30 PM

WP7 applications are sandboxed to, So it will prevent applications accessing each other's data !

Thus you can try saving it in the
IsolatedStroage


Check this Example from MSDN:

private void btnWrite_Click(object sender, RoutedEventArgs e)
{
    // Obtain the virtual store for the application.
    IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();

    // Create a new folder and call it "MyFolder".
    myStore.CreateDirectory("MyFolder");

    // Specify the file path and options.
    using (var isoFileStream = new IsolatedStorageFileStream("MyFolder\\myFile.txt", FileMode.OpenOrCreate, myStore))
    {
        //Write the data
        using (var isoFileWriter = new StreamWriter(isoFileStream))
        {
            isoFileWriter.WriteLine(txtWrite.Text);
        }
    }
}





// This code opens and reads the contents of myFile.txt.
private void btnRead_Click(object sender, RoutedEventArgs e)
{
    // Obtain a virtual store for the application.
    IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();

    try
    {
        // Specify the file path and options.
        using (var isoFileStream = new IsolatedStorageFileStream("MyFolder\\myFile.txt", FileMode.Open, myStore))
        {
            // Read the data.
            using (var isoFileReader = new StreamReader(isoFileStream))
            {
                txtRead.Text = isoFileReader.ReadLine();
            }
        }

    }
    catch
    {
        // Handle the case when the user attempts to click the Read button first.
        txtRead.Text = "Need to create directory and the file first.";
    }
}






Source:

:rolleyes: :innocent: :chinese: :chinese:
Was This Post Helpful? 0
  • +
  • -

#3 babbu25  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 68
  • Joined: 26-November 11

Re: How to Include a File to read values in Windows Mobile Application

Posted 25 March 2012 - 01:39 PM

hi

Thank u for the response Observer

The problem is that i am not working on WP 7 .I have to do it in windows application.I do not see the

IsolatedStorage Option in my windows form ..There has to be some other way for windows Application other than This ..any ideas?

Thanks
Was This Post Helpful? 0
  • +
  • -

#4 TheObserver  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 12-March 12

Re: How to Include a File to read values in Windows Mobile Application

Posted 25 March 2012 - 02:01 PM

View Postbabbu25, on 25 March 2012 - 11:39 PM, said:

windows Application
:blink: :blink: This is the WindowsPhone Section, no wonder you didn't get any reply!

Never mind I'm stuck with my project as well, but here is how you do it!

make sure to include
using System.IO;



Create a Button and a TextBox.

Paste this in the Click_Event of the Button:
StreamReader objstream = new StreamReader("C:\\Users\\Read Text.txt");


Change the Path to your text File Path!

and make the Value of the TextBox like this:


textBox1.Text = objstream.ReadLine();


If you want to get the whole text use [code]ReadToEnd 
instead of
ReadLine



Is that Good ? -.-
[/code]
Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1525
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: How to Include a File to read values in Windows Mobile Application

Posted 25 March 2012 - 05:10 PM

View PostTheObserver, on 25 March 2012 - 05:01 PM, said:

View Postbabbu25, on 25 March 2012 - 11:39 PM, said:

windows Application
:blink: :blink: This is the WindowsPhone Section, no wonder you didn't get any reply!


We use this forum for all Windows Phone OS's including Windows Phone 7, and Windows Mobile.

If the file is in the root directory of the application, then you may want to use..

string dir = Environment.CurrentDirectory;
string filePath = Path.Combine(dir, "Project.txt");

if (File.Exists(filePath))
{
   // your code
}


Was This Post Helpful? 0
  • +
  • -

#6 babbu25  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 68
  • Joined: 26-November 11

Re: How to Include a File to read values in Windows Mobile Application

Posted 25 March 2012 - 07:40 PM

hi eclipsed4utoo



I have tried this thing



string dir = Environment.CurrentDirectory;




But i am not able to get my file path.

My File is in the root directory and when i try to access using the above code

I get an error telline

"System.Environment does not contain a definition for CurrentDirectory"



I tried using this instead
string dir = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string filePath = Path.Combine(dir, "Test.txt");





I AM trying to get the my documents folder and created a File name "Test.txt"..Still it wont detect that it has a file .I am like totally struck up at this part

Help is mostly Appreciated
Thank you
Was This Post Helpful? 0
  • +
  • -

#7 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1525
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: How to Include a File to read values in Windows Mobile Application

Posted 26 March 2012 - 05:10 AM

Is the file actually there in the My Documents directory on the emulator? If so, put a breakpoint on the line that checks if the file exists and look at the directory path that was created. Make sure it's going to the correct place.
Was This Post Helpful? 0
  • +
  • -

#8 Quizton  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 18-April 12

Re: How to Include a File to read values in Windows Mobile Application

Posted 21 September 2012 - 07:58 AM

Hello,

have you checked to see if the file exists where it should? FindingExistingFilesAndDirectories Example

within isostore

Also might just go thru vis studio cmd and manually create the path.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1