Read From Text File in Windows 8 Apps/Windows Phone 8 Apps - vb.net

If I'm going in the wrong direction, please feel free to give me some guidance!
I'm having trouble understanding the use of streams in the Visual Studio for Windows 8 Apps and Windows 8 Phone Apps environment.
All I want to do is read some text from a file into a string. Here's my simple code that I would use for Visual Studio for Windows Desktop:
Sub ReadFromFileTest()
Dim FilePath As String = "c:\2012\Projects\VBDesktopTest\Test.txt"
Dim ReadString As String
Dim Reader As New System.IO.StreamReader(FilePath)
ReadString = Reader.ReadLine()
Do Until ReadString Is Nothing
OutputListBox.Items.Add(ReadString)
ReadString = Reader.ReadLine()
Loop
Reader.Close()
Reader.Dispose()
End Sub
This same code in Visual Studio for Windows 8 Applications generates an error: "value of type 'string' cannot be converted to 'system.io.stream'". I've looked through the list of constructors for the StreamReader class and I see that StreamReader(file name as string) is not supported in ".NET for Windows Store apps". It seems I need to use the StreamReader(stream) constructor but I can't seem to figure out how to make a make my file into a stream.
My ultimate goal is to create a simple app for Windows Phone 7.1 that looks up and returns information from a list of equipment stored in a text file. I'm starting with Windows 8 so as not to further confuse myself with the phone emulator.

See I have no idea of Vb .net But I am sharing the c# code (function) that serves the purpose for windows phone
private string ReadFile(string filePath)
{
//this verse is loaded for the first time so fill it from the text file
var ResrouceStream = Application.GetResourceStream(new Uri(filePath, UriKind.Relative));
if (ResrouceStream != null)
{
Stream myFileStream = ResrouceStream.Stream;
if (myFileStream.CanRead)
{
StreamReader myStreamReader = new StreamReader(myFileStream);
//read the content here
return myStreamReader.ReadToEnd();
}
}
return "NULL";
}
The answer i took is from this link
Reading files from stream windows phone

Related

Display upload and download speed values of the device in UWP application[Windows 10 anniversary edition(10.0;Build 14393) ](vb.net)

With reference to the link https://stefanwick.com/2018/04/06/uwp-with-desktop-extension-part-1/ I tried the following methodology. However, I am getting errors. The steps followed are as follows:
Development Environment: Microsoft Visual Studio Enterprise 2017,Version 15.9.23 enter code here
1.Created a console application(c#) that calls an external non visual studio internet speed calculation exe and retrieved the download and upload values and assigned them to ValueSet variables.
Also added ‘AppServiceConnection’ to send the results to UWP based on request from UWP.
static AppServiceConnection connection = null;
connection = new AppServiceConnection();
connection.AppServiceName = "xyz";
connection.PackageFamilyName = Windows.ApplicationModel.Package.Current.Id.FamilyName;
connection.RequestReceived += Connection_RequestReceived;
AppServiceConnectionStatus status = await connection.OpenAsync();
private static void Connection_RequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
{
//added code to call the external exe file
ValueSet valueSet = new ValueSet();
valueSet.Add("Upload", upload);
valueSet.Add("Download", download);
args.Request.SendResponseAsync(valueSet).Completed += delegate { };
}
Note: • Set the output type of the Console Application to -> Properties->Application->outputtype -> WindowsApplication • Target Framework of Console Application : .NET Framework 4.6.1
Created a UWP application
• Added reference to Windows Desktop Extension for UWP. • Added code in Page.xaml.vb (UWP) :On click of Listview link “Calculate Internet Speed”
If(ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract", 1, 0)) Then Await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync("Background") End If
• Added following code in App.xaml.vb (UWP)
Protected Overrides Sub OnBackgroundActivated(ByVal args As BackgroundActivatedEventArgs)
MyBase.OnBackgroundActivated(args)
Dim taskInstance As IBackgroundTaskInstance = args.TaskInstance
Dim AppService As AppServiceTriggerDetails = TryCast(taskInstance.TriggerDetails, AppServiceTriggerDetails)
_appServiceDeferral = taskInstance.GetDeferral()
AddHandler taskInstance.Canceled, AddressOf OnAppServicesCanceled
AddHandler _appServiceConnection.RequestReceived, AddressOf OnAppServiceRequestReceived
AddHandler _appServiceConnection.ServiceClosed, AddressOf AppServiceConnection_ServiceClosed
_appServiceConnection = AppService.AppServiceConnection
End Sub
Private Sub OnAppServiceRequestReceived(ByVal sender As AppServiceConnection, ByVal args As AppServiceRequestReceivedEventArgs)
Dim messageDeferral As AppServiceDeferral = args.GetDeferral()
Dim Upload As String = args.Request.Message("Upload").ToString()
Dim Download As String = args.Request.Message("Download").ToString()
messageDeferral.Complete()
End Sub
3)Created a UWP Package: • Applications :Added Console Application( Output type as Windows Application) and UWP application • Package.appmanifest:
• Set the UWP application as Entry Point
Configuration : • UWP package- ‘Deploy’ • UWP application and UWP package – ‘x86’ platform After build, I get the following issues:
.pdb files not loaded
Networkinformationfactory.cpp not found
On reaching this part of code,
Await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync("Background")
The following error shows up
‘.WinTypes.pdb not loaded’

Adobe PDF Ifilter 11 and 9 on Win 10 not working

I'm trying to use Adobe PDF Ifilter 11 on Win 10 to extract text from PDF files via a general Ifilter text extraction program in c#. The program contains the following code
private static NativeMethods.IFilter LoadFilterFromDll(string dllName, string filterPersistClass)
{
// Get a classFactory for our classID
var classFactory = ComHelpers.GetClassFactory(dllName, filterPersistClass);
if (classFactory == null)
return null;
// And create an IFilter instance using that class factory
var filterGuid = new Guid("89BCB740-6119-101A-BCB7-00DD010655AF");
Object ppunk;
classFactory.CreateInstance(null, ref filterGuid, out ppunk);
return (ppunk as NativeMethods.IFilter);
}
Usiing the Adobe PDF IFlter 11 (and IFilter 9). The CreateInstance call is very slow to execute and when the text is extracted is called the message
Error HRESULT E_FAIL has been returned from a call to a COM component.
appears.
Text extraction works OK with the PDFLib TET Ifilter.
Adobe Reader DC is installed.
Does anyone know a workaround that would allow an Adobe PDF IFilter to be used?

twilio nuget package not sending SMS message in vb.net

Does the twilio asp.net helper library package NOT work in vb.net? I can get it to work in c# web app but not vb.net web app.
In a vb.net web application project the following code doesnt send an sms message and when stepping through with the debugger, errs on the send message line and brings up a file dialog asking for access to core.cs. The twilio library's were installed via nuget.
Public Shared Sub SendAuthCodeViaSms(ByVal number As String)
Dim twilioAccountInfo As Dictionary(Of String, String) = XmlParse.GetAccountInfoFromXmlFile("twilio")
Dim accountSid As String = twilioAccountInfo("username")
Dim authToken As String = twilioAccountInfo("password")
If (Not String.IsNullOrEmpty(accountSid) AndAlso Not String.IsNullOrEmpty(authToken)) Then
Dim client = New TwilioRestClient(accountSid, authToken)
client.SendMessage(TwilioSendNumber, ToNumber, "Testmessage from My Twilio number")
Else
'log error and alert developer
End If
End Sub
But in a C# web API project the same code sends the message as expected.
protected void Page_Load(object sender, EventArgs e)
{
const string AccountSid = "mysid";
const string AuthToken = "mytoken";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var message = twilio.SendMessage(TwilioSendNumber,ToNumber,"text message from twilio");
}
and all the sid's and tokens and phone number formats are correct, otherwise the c# one wouldnt send and I wouldnt get to the client.SendMessage part of vb.net version (client.SendSMSMessage produces the same result)
Twilio evangelist here.
I tried our your code by creating a simple VB console app and it worked for me.
The only thing I can think of is that either you are not getting your Twilio credentials correctly when parsing the XML, or the phone number you are passing into the function is not formatted correctly.
I'd suggest putting the result of call to SendMessage() into a variable and checking to see if RestException property is null:
Dim result = client.SendMessage(TwilioSendNumber, ToNumber, "Testmessage from My Twilio number")
If (Not IsNothing(result.RestException)) Then
' Something bad happened
Endif
If Twilio returns a status code greater than 400, then that will show up as an exception in the RestException property and will give you a clue as to whats going on.
If that does not work, you can always break out a tool like Fiddler to watch and see if the library is making the property HTTP request and Twilio is returning the proper result.
Hope that helps.

windows 8 store FTP

I'm building a windows store application in VB.net, and when I try to get the certification, so I can publish it in the store, it fails the API test, because it doesn't accept the fact that I used AlexPilotti's FTPSClient dll.
The only thing I have to do is to upload a small video to the ftp server. Pretty simple, right? It's working properly, both in PC and Tablet, the only problem is the certification.
I had to use AlexPilotti's FTPSClient dll because "ftpwebrequest" is gone from Windows Store.
So, I wonder if there is anything else I can try, maybe a windows store compatible dll?
I have tried BackgroundTransfer, but apparently it only works with HTTP and HTTPS, not FTP.
I've been trying to find an answer for a few days now, but what I find never seems to work.
Thanks in advance!
Found this example by searching but didn't test it. Google is a programmers best friend.
Public Async Function FTP_Uploader(ftpURL As String, filename As String, username As String, password As String, UploadText As String) As Task(Of Boolean)
Try
Dim request As WebRequest = WebRequest.Create(ftpURL + "/" + filename)
request.Credentials = New System.Net.NetworkCredential(username.Trim(), password.Trim())
request.Method = "STOR"
Dim buffer As Byte() = Encoding.UTF8.GetBytes(UploadText)
Dim requestStream As Stream = Await request.GetRequestStreamAsync()
Await requestStream.WriteAsync(buffer, 0, buffer.Length)
Await requestStream.FlushAsync()
Return True
Catch ex As Exception
Return False
End Try End Function

Converting TIFF to PDF results in Insufficient Data For Image

I have a utility that converts batches of TIFF images to PDFs using the PDFSharp library. The following code performs the actual conversion. When I open the resulting PDF files in Acrobat Reader, I receive an error message for certain ones stating "Insufficient Data for Image." Others are fine.
What could be causing this? Is there anything I'm missing in the code that could prevent this?
Public Shared Function ConvertImageToPDF(ByVal img As Image) As Byte()
Using ms As New MemoryStream()
Using pdf As New PdfDocument()
Dim pageCount = GetPageCount(img)
For index = 0 To (pageCount - 1)
Dim page = New PdfPage()
Using sourceImage = GetPage(img, index)
Using pageImage = XImage.FromGdiPlusImage(sourceImage)
page.Width = pageImage.PointWidth
page.Height = pageImage.PointHeight
pdf.Pages.Add(page)
Using xgr = XGraphics.FromPdfPage(pdf.Pages(index))
xgr.DrawImage(pageImage, 0, 0)
End Using
End Using
End Using
Next
pdf.Save(ms, False)
pdf.Close()
End Using
Return ms.ToArray()
End Using
End Function
Public Shared Function GetPageCount(ByVal img As Image) As Integer
If (img Is Nothing) Then
Return -1
End If
Return img.GetFrameCount(FrameDimension.Page)
End Function
Public Shared Function GetPage(ByVal img As Image, ByVal pageNumber As Integer) As Image
img.SelectActiveFrame(FrameDimension.Page, pageNumber)
Dim ms = New MemoryStream()
img.Save(ms, ImageFormat.Tiff)
Return Image.FromStream(ms)
End Function
UPDATE:
If I run the same code over the same TIFF files, then the PDF files that were corrupt before are now OK, and ones that were OK before are now corrupt.
UPDATE 2:
After reviewing this connect issue (https://connect.microsoft.com/VisualStudio/feedback/details/584681/system-drawing-image-flags-has-different-value-in-vista-and-windows-7) and the community comment on this MSDN page (http://msdn.microsoft.com/en-us/library/system.drawing.image.save.aspx), it appears the issue is related to an operating system level bug in Windows 7. Can anyone confirm this or offer a workaround?
As stated in my update, after reviewing this connect issue (https://connect.microsoft.com/VisualStudio/feedback/details/584681/system-drawing-image-flags-has-different-value-in-vista-and-windows-7) and the community comment on this MSDN page (http://msdn.microsoft.com/en-us/library/system.drawing.image.save.aspx), it appears the issue is related to an operating system level bug in Windows 7.
This is supported by the comment from PDFsharpTeam.
In addition, when the images are read in Windows XP, the flags property on the image object is set to 77888. On Win7, it is set to 77840. After reviewing the MSDN documentation for the flags property (http://msdn.microsoft.com/en-us/library/system.drawing.image.flags.aspx), the difference is that WinXP flagged the image as a grayscale image (which mine are), but Win7 flagged it as an RGB image. This appears to be a symptom of the problem, but I don't know enough about image formats and color spaces to speak with authority on this.
UPDATE (2014-06-13):
After continuing to experience this problem, I researched a bit further and found a post on the PDFSharp forums mentioning this issue and linking to another post with a fix.
http://forum.pdfsharp.net/viewtopic.php?f=2&t=2729
http://forum.pdfsharp.net/viewtopic.php?p=5967#p5967
Basically, there are two methods in the PdfImage.FaxEncode.cs file that need to be updated.
In both the CountOneBits() and CountZeroBits() methods, replace the following code:
return found + hits;
with
found += hits;
if (found >= bitsLeft)
return bitsLeft;
return found;