VB RS.exe - DataSource is not defined - vb.net

I have this code to programmatically export a report to PDF.
Public Sub Main()
TRY
DIM historyID as string = Nothing
DIM deviceInfo as string = Nothing
DIM extension as string = Nothing
DIM encoding as string
DIM mimeType as string = "application/Excel"
DIM warnings() AS Warning = Nothing
DIM streamIDs() as string = Nothing
DIM results() as Byte
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim dataSources() As DataSource = rs.GetItemDataSources("foldername/reportname")
rs.LoadReport(REPORTSERVER_FOLDER, historyID)
results = rs.Render(FORMAT, deviceInfo, extension, mimeType, encoding, warnings, streamIDs)
DIM stream As FileStream = File.OpenWrite(FILENAME)
stream.Write(results, 0, results.Length)
stream.Close()
Catch e As IOException
Console.WriteLine(e.Message)
End Try
End Sub
When I run it I get an error saying:
error BC30002: Type 'DataSource' is not defined.
Dim dataSources() As DataSource = rs.GetItemDataSources("foldername/reportname")
~~~~~~~~~~
Am I forgetting to import something? If I remove that line it works fine (besides that it needs a data source to be added). Adding the data source beforehand is not an option.

So I figured the answer. I am using the Exec2005 (execution endpoint), which does not include the definition for DataSource. I should instead use the default endpoint (Mgmt2005), but this causes other problems in the code.
In any case, the answer to this question is to not use -e Exec2005.

Related

VB.NET Return Form Object using Form Name

I'm basically writing a custom Error Logging Form for one of my applications because users cannot be trusted to report the errors to me.
I am obtaining the Form Name using the 'MethodBase' Object and then getting the DeclaringType Name.
Dim st As StackTrace = New StackTrace()
Dim sf As StackFrame = st.GetFrame(1)
Dim mb As MethodBase = sf.GetMethod()
Dim dt As String = mb.DeclaringType.Name
How can I then use this to obtain the Form Object so I can pass this to my 'screenshot method' that screenshots the particular form referenced.
Public Sub SaveAsImage(frm As Form)
'Dim fileName As String = "sth.png"
'define fileName
Dim format As ImageFormat = ImageFormat.Png
Dim image = New Bitmap(frm.Width, frm.Height)
Using g As Graphics = Graphics.FromImage(image)
g.CopyFromScreen(frm.Location, New Point(0, 0), frm.Size)
End Using
image.Save(_LogPath & Date.Now.ToString("ddMMyyyy") & ".png", format)
End Sub
I posted the same solution to a similar question. Try this:
Dim frm = Application.OpenForms.Item(dt)

How to cast COM object of type 'System.__ComObject' to interface type 'ESRI.ArcGIS.Carto.FeatureLayer' in vb.net?

Private Function GetRaster(ByRef sLayerLocation As String) As ESRI.ArcGIS.Carto.FeatureLayer
Dim fso As New Scripting.FileSystemObject
Dim sFolder As String
Dim sFile As String
Dim pWsFact As ESRI.ArcGIS.Geodatabase.IWorkspaceFactory
Dim pRasterWs As ESRI.ArcGIS.Geodatabase.IRasterWorkspace2
Dim pRasterDataset As ESRI.ArcGIS.Geodatabase.IRasterDataset
Dim pRaster As ESRI.ArcGIS.Geodatabase.IRaster
Dim pRasterLayer As ESRI.ArcGIS.Carto.IRasterLayer
sFolder = fso.GetParentFolderName(sLayerLocation)
sFile = fso.GetFileName(sLayerLocation)
Try
'Open the workspace
pWsFact = New ESRI.ArcGIS.DataSourcesRaster.RasterWorkspaceFactory
pRasterWs = pWsFact.OpenFromFile(sFolder, 0)
'Open the raster dataset
pRasterDataset = pRasterWs.OpenRasterDataset(sFile)
pRasterLayer = New ESRI.ArcGIS.Carto.RasterLayer
pRasterLayer.CreateFromDataset(pRasterDataset)
pRaster = pRasterLayer.Raster
**GetRaster = pRaster;**
Catch ex As Exception
End Try
In above code snippet while trying to assign pRaster to GetRaster the code statement is throwing exception "Unable to cast COM object of type 'System.__ComObject' to interface type 'ESRI.ArcGIS.Carto.FeatureLayer" . I tried casting also but that too not working. Any help will be appreciated.
Raster layers don't implement IFeatureLayer interface. Except raster catalog layers I think.
Your function should return IRasterLayer or IRaster.

Error with UltraID3Lib VB

Well I get this error (The ID3v2TagVersions value of '4' (4) is not valid for this operation.) with UltraID3Lib on Visual Basic 2013. I want to use this library (dll) so i can edit my mp3 tags in a mp3 file. Although I achived changing the tags , when i use the Clear() sub and then retry to change the tags i get this error. Can anyone help me ?
My Code
Private Sub btnExecute_Click(sender As Object, e As EventArgs) Handles btnExecute.Click
Dim Artist As String = ""
Dim Title As String = ""
Dim MP3TagEditor As New UltraID3
For Each Path In MP3List
MP3TagEditor.Read(Path)
Title = "Somthing"
Artist = "Somthing"
MP3TagEditor.ID3v2Tag.Title = Title
MP3TagEditor.ID3v2Tag.Artist = Artist
MP3TagEditor.Clear()
MP3TagEditor.Write()
Next
MsgBox("Tags Added", MsgBoxStyle.Information, "Success")
End Sub
Thanks
Try this
Dim sTitle As String = "No Name"
Dim sSinger As String = ""
Dim sAlbum As String = ""
Dim sYear As String = ""
Dim sComm As String = ""
Dim MP3Tag As New UltraID3
MP3Tag.Read(YOUR_PATH)
Try
Dim pics = MP3Tag.ID3v2Tag.Frames.GetFrames(CommonMultipleInstanceID3v2FrameTypes.Picture)
AlbumPic.Image = CType(pics(0), ID3v2PictureFrame).Picture
Catch ex As Exception
AlbumPic.Image = My.Resources.FlatCD
End Try
Try
sTitle = MP3Tag.Title
sSinger = MP3Tag.Artist
sAlbum = MP3Tag.Album
Catch ex As Exception
End Try
You cannot read ID3v2.4 tags from an MP3 file with UltraID3Lib. It doesn't support it yet. (As of 31/12/2015).
But there is an alternative, which, in my humble opinion is even better, stable and efficacious:
TagLib-Sharp
It supports many other tag types as well apart from ID3, i.e, MP3 Files.
A quick example to get you on the way:
Dim f As TagLib.File = TagLib.File.Create("someFile.mp3")
Dim artist As String = f.Tag.JoinedPerformers
Dim title As String = f.Tag.Title
More resources for TagLib-Sharp:
Where can I find tag lib sharp examples?
Set Bitmap as cover art for MP3

Identify the file type of a File / Stream - VB.Net

I have a problem when I download a file from a URL (This it's not my main problem), the problem comes after that.
The file that I saved from the URL can be a image, doc, PDF or ZIP.
Exists some method to know the file type when the path doesn't has the extension?
Or identify the file type from an stream?
I'm working with Visual Studio 2010 Express Edition - Framework.Net 3.5 - A Window App
Public Function DownloadFile_FromURL(ByVal URL As String, ByVal DestinationPath As String) As Boolean
DownloadFile_FromURL = False
Try
Dim vRequest As Net.HttpWebRequest
Dim vResponse As Net.HttpWebResponse
vRequest = Net.WebRequest.Create(New Uri(URL))
vRequest.Method = "GET"
vRequest.AllowAutoRedirect = True
vRequest.UseDefaultCredentials = True
vResponse = vRequest.GetResponse
If vResponse.ContentLength <> -1 Then
Dim vLen As Long = vResponse.ContentLength
Dim vWriteStream As New IO.FileStream(DestinationPath, IO.FileMode.CreateNew)
Dim vStream As IO.Stream = vResponse.GetResponseStream()
Dim vReadBytes() As Byte = New Byte(255) {}
Dim vCount As Integer = vStream.Read(vReadBytes, 0, vReadBytes.Length)
While vCount > 0
vWriteStream.Write(vReadBytes, 0, vCount)
vCount = vStream.Read(vReadBytes, 0, vReadBytes.Length)
End While
vWriteStream.Flush() : vWriteStream.Close()
vResponse.Close() : vRequest = Nothing : GCcleaner()
Dim v = System.IO.Path.GetExtension(DestinationPath)
DownloadFile_FromURL = True
End If
Catch ex As Exception
Throw New Exception(ex.mc_GetAllExceptions)
End Try
End Function
If you are using WebRequest for the download.
Dim uri As String = "http://domain.com/resource"
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(uri), HttpWebRequest)
request.Method = "GET"
Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
Dim contentType = response.ContentType
' this will have the content type/ file type
You can now have a routine to save the file using a particular extension depending on the content type. for instance a content type of "image/jpeg" can be saved as *.jpg
For an Image you can load it into an Image() object and see if it throws an OutOfMemoryException -- not an image.
PDF you can read the first few bytes of it (the PDF file type info is stored there, though not sure exactly what it is at the moment).
ZIP and DOC I'm not sure about.
If you are using WebRequests you can grab the content type of the response stream. More information about the MIME/content types here: http://msdn.microsoft.com/en-us/library/ms775147.aspx

Converting UTF8 to ANSI?

I'd like to download a webpage using .Net's WebClient class, extract the title (i.e. what's between <title> and </title>) and save the page to a file.
The problem is, the page is encoded in UTF-8 and the System.IO.StreamWriter throws an exception when using a filename with such characters.
I've googled and tried several ways to convert UTF8 to ANSI, to no avail. Does someone have working code for this?
'Using WebClient asynchronous downloading
Private Sub AlertStringDownloaded(ByVal sender As Object,
ByVal e As DownloadStringCompletedEventArgs)
If e.Cancelled = False AndAlso e.Error Is Nothing Then
Dim Response As String = CStr(e.Result)
'Doesn't work
Dim resbytes() As Byte = Encoding.UTF8.GetBytes(Response)
Response = Encoding.Default.GetString(Encoding.Convert(Encoding.UTF8,
Encoding.Default, resbytes))
Dim title As Regex = New Regex("<title>(.+?) \(",
RegexOptions.Singleline)
Dim m As Match
m = title.Match(Response)
If m.Success Then
Dim MyTitle As String = m.Groups(1).Value
'Illegal characters in path.
Dim objWriter As New System.IO.StreamWriter("c:\" & MyTitle & ".txt")
objWriter.Write(Response)
objWriter.Close()
End If
End If
End Sub
Edit: Thanks everyone for the help. It turns out the error was not due to UTF8 but rather a hidden LF character in title section of the page, which is obviously an illegal character in a path.
Edit: Here's a simple way to remove some of the illegal characters in a filename/path:
Dim MyTitle As String = m.Groups(1).Value
Dim InvalidChars As String = New String(Path.GetInvalidFileNameChars()) + New String(Path.GetInvalidPathChars())
For Each c As Char In InvalidChars
MyTitle = MyTitle.Replace(c.ToString(), "")
Next
Edit: And here's how to tell WebClient to expect UTF-8:
Dim webClient As New WebClient
AddHandler webClient.DownloadStringCompleted, AddressOf AlertStringDownloaded
webClient.Encoding = Encoding.UTF8
webClient.DownloadStringAsync(New Uri("www.acme.com"))
I don't think the problem is related to UTF-8. I think your regex will include </title> if it appears on the same line. The characters<> are invalid in a Windows filename.
If this is not the problem it would be helpful to see some sample input and output values of MyTitle.