var file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Storage.txt");
what value does the "file" variable contain? I Think you have the path of the file inside it
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Here's my MainPage.xaml
:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:VM="clr-namespace:Emon"
x:Class="Emon.MainPage">
<ContentPage.BindingContext>
<VM:MainVM/>
</ContentPage.BindingContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackLayout Margin="20,20,20,0">
<Entry Placeholder="First Name" Text="{Binding FirstName}"/>
<Entry Placeholder="Last Name" Text="{Binding LastName}" />
<Button Text="Send Name" Command="{Binding Send}"/>
</StackLayout>
<ListView Grid.Row="1" ItemsSource="{Binding Infos}"/>
</Grid>
</ContentPage>
When I click Send
Button, it sends FirstName and LastName to a Server and the Server, in response, sends back some string to the android client. Android client then stores the info, sent by server, in a text file, Storage.txt
. Here's all the logic in ViewModel, MainVM.cs
:
public class MainVM : INotifyPropertyChanged
{
string fName, lName;
public string FirstName
{
get { return fName; }
set { fName = value; Send.ChangeCanExecute(); }
}
public string LastName
{
get { return lName; }
set { lName = value; Send.ChangeCanExecute(); }
}
public ObservableCollection<string> Infos{ get; set; }
public Command Send { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
public MainVM()
{
Send = new Command(send, canSend);
Infos= new ObservableCollection<string>();
}
void send()
{
var sock = new Socket(SocketType.Stream, ProtocolType.Tcp);
sock.Connect(new IPEndPoint(IPAddress.Parse("***.***.***.106"), 5555));
sock.Send(Encoding.ASCII.GetBytes(FirstName + " " + LastName));
var data = new byte[128];
sock.Receive(data);
var info = Encoding.ASCII.GetString(data);
Infos.Add(info);
sock.Shutdown(SocketShutdown.Both);
sock.Close();
sock.Dispose();
var file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Storage.txt");
var writer = new StreamWriter(file, true, Encoding.ASCII);
writer.WriteLine(info);
writer.Close();
writer.Dispose();
FirstName = string.Empty; LastName = null;
OnPropertyChanged(nameof(FirstName));
OnPropertyChanged(nameof(LastName));
}
bool canSend() => !string.IsNullOrWhiteSpace(FirstName) && !string.IsNullOrWhiteSpace(LastName);
void OnPropertyChanged(string name) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
After finishing the send/receive operation I'd connected the android device to my computer via USB cable and found two folders, cache and files, in my app location, ie, This PC\V75\Internal storage\Android\data\com.companyname.emon
BUT neither of those contain any file named Storage.txt
.
Where does it save files?
var file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Storage.txt");
what value does the "file" variable contain? I Think you have the path of the file inside it