how to make VB count the number of items available in a folder of my website? i need to use FTP? i can make VB upload files, download files, or whatever,all using FTP, but i need him show me how many items i have in the specific folder.
I use this code for connect to FTP:
Dim request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create("adress"), System.Net.FtpWebRequest)
request.Credentials = New System.Net.NetworkCredential("user", "pass")
You can list the files in the directory using the method ListDirectoryDetails:
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
Related
I'm trying to pass credentials to the ssrs server to load the report as PDF but am getting 401 unauthorized error.
I have a vb.net web forms project that I'm working on and it is trying to load a report on a remote SQL Server 2008 r2 machine. I'm trying to load the report and have it download as a pdf. My code is supposed to load the file as a data stream which allows the user to save the file. Pointing the browser directly to the url of the report, I can get the PDF, but need to supply credentials. I'm trying to avoid the need to login to get the report. The code I'm using is supposed to pass credentials but instead of returning the report, I get 401 unauthorized error.
Dim ReportUrl As String = "http://server/ReportServer/Pages/ReportViewer.aspx?%2fReport%2fParishreport&rs:Command=Render¶meter=" & session("parameter") & "&rs:format=pdf"
Dim ReportWebResponse As HttpWebResponse
Dim Request As HttpWebRequest = CType(WebRequest.Create(ReportUrl), HttpWebRequest)
'Request.Credentials = CredentialCache.DefaultCredentials
Request.Credentials = New NetworkCredential("user", "password")
ReportWebResponse = CType(Request.GetResponse(), HttpWebResponse)
Dim ReportResponseStream As StreamReader = New StreamReader(ReportWebResponse.GetResponseStream(), New UnicodeEncoding)
Dim objMemoryStream As New MemoryStream(New UnicodeEncoding().GetBytes(ReportResponseStream.ReadToEnd()))
Response.Clear()
Response.AddHeader("Accept-Header", objMemoryStream.Length.ToString())
Response.ContentType = "application/pdf"
Response.OutputStream.Write(objMemoryStream.ToArray(), 0, Convert.ToInt32(objMemoryStream.Length))
ReportResponseStream.Close()
Response.Flush()
Try
Response.End()
Catch
End Try
I expected the browser to allow me to save the PDF or to display the pdf in the browser(Firefox built in PDF viewer). Using specified username and password, I get 401 unauthorized error. Using defaultcredentials, I get a blank PDF of the correct number of pages.
I have added the domain account to the report server: 1. using SQL server management studio 2. using report server web interface adding folder and report permissions.
What is the preferred method for supplying credentials to the reporting server such that a single domain account can be used to control users ability to view the report?
I have a working code to download many files (hundreds) from an FTP server, but it's very slow and often a timeout error appears.
This is my current way of doing the downloads:
Using ftpClient As New WebClient()
ftpClient.Credentials = New System.Net.NetworkCredential(ftpuser, ftppassword)
For i As Integer = 0 To directoriesDownload.Count - 1
If directoriesDownload(i).Contains(".") Then
If Sync_BackgroundWorker.CancellationPending = True Then
Exit Sub
End If
Dim path As String = "ftp://" & ftpserver & "Datenbank/" + directoriesDownload(i).ToString()
Dim trnsfrpth As String = config.rootpath & "ServerDownload\" + directoriesDownload(i).ToString()
ftpClient.DownloadFile(path, trnsfrpth)
filenametodownload = directoriesDownload(i).ToString()
filesdownloaded += 1
Sync_BackgroundWorker.ReportProgress(filesdownloaded)
End If
Next
ftpClient.Dispose()
End Using
Is there any faster way of downloading hundreds of small files (up to 10 KB) from an FTP server in VB.NET?
It would be the best if there is an option to sign into the FTP only once instead of logging in and out for every file.
I found somebody else having the same problem but without a working result:
Using FTP to download each file *WHILE* getting the file list
I also tried multithreading with a Parallel.For loop, but WebClient does not work with multithreading. Same thing if I try with ftpClient.DownloadFileAsync(New Uri(path), trnsfrpth).
Is there any faster way of downloading hundreds of small files (up to 10 KB) from an FTP server in VB.NET?
...
I also tried multithreading with a Parallel.For loop, but WebClient does not work with multithreading. Same thing if I try with ftpClient.DownloadFileAsync(New Uri(path), trnsfrpth).
Multithreading is the way to go. It's not true that WebClient does not support multithreading. Why wouldn't it?
If you have a problem with implementing multithreaded FTP transfers, you should ask a question about that, rather than asking a question about other (and probably non-existent) ways.
It would be the best if there is an option to sign into the FTP only once instead of logging in and out for every file.
Your code does sign into FTP only once.
See C# - FtpWebRequest - Multiple requests over the same connection/login - What is written there about FtpWebRequest is equally true for WebClient, as WebClient uses FtpWebRequest internally.
I know there are several solutions in other languages but I can't find anything in VB.NET.
I have a file containing the "software version" on an FTP server, however everytime the program tries to read it through the WebBrowser, it picks up an old version of it. In other words the cached version.
Is there anything that can use to clear the cache for just the one file?
Code so far:
Dim WebBR As New WebBrowser
WebBR.Navigate("URL\Version.txt", False)
Do Until WebBR.ReadyState = WebBrowserReadyState.Complete
Application.DoEvents()
Loop
Dim VRB = WebBR.Document.Body.InnerHtml
VRB = VRB.Replace("<PRE>", "")
VRB = VRB.Replace("</PRE>", "")
NewVersion = VRB
If NewVersion <> CurrentVersion Then
Return True
Else
Return False
End If
Why do you read the file though web browser? That's an overkill.
Use the FtpWebRequest. It does not have any cache.
See also:
Upload and download a binary file to/from FTP server in C#/.NET
How to: Download Files with FTP.
I have attempted to find a way to download a file (from a PC running a Winform written in VB) from a web directory but could not get this done due to the date stamp that gets generated once the file is saved (filename must be precise). So now I'm trying the reverse (saving the file to the PC directly from the creation of the file).
Does anyone have any suggestions on methods to use (please no FTP due to proxy restrictions, same goes for client/server TCP/UDP). this will always be a .txt file.
thanks in advance.
If you can see the file contents by navigating to the URL, you can use an HttpWebRequest and a StreamReader / StreamWriter to save the data.
I'm downloading an example from http://textfiles.com/100/914bbs.txt
Dim request As HttpWebRequest
request = WebRequest.Create("http://textfiles.com/100/914bbs.txt")
request.Method = "GET"
Dim response = request.GetResponse
Using reader As New StreamReader(response.GetResponseStream)
Using writer As New StreamWriter("C:\myfilename.txt")
writer.Write(reader.ReadToEnd)
End Using
End Using
I have a class library which reads the XML file.
I am using VS 2012 and VB.NET language.
I am getting confused about how to read the file which is in folder of a application itself.
Right now I have given the path as
Dim reader As XmlTextReader = New XmlTextReader("C:\mailpara.xml")
but its hard-coded , but I want to make a folder in app. and want to read from that
folder itself.
I want to know how to read the file from the folder of a application.
How to read the file after installation on client's machine and how to add the file while making the set up ?
Use something like;
Dim directory as String = My.Application.Info.DirectoryPath
Dim reader As XmlTextReader = New XmlTextReader(directory & "\MyFolderName\mailpara.xml")
You can use Application.StartupPath property to retrieve the startup path of the application.
Dim reader As XmlTextReader = New XmlTextReader(Application.StartupPath & "mailpara.xml")
You might want to add a check to ensure that the path ends with a \ (I think it may or may not be present depending on whether the path is a root folder or not).