Hi,
I'm writing a custom delivery extension that saves the rendered report
to the disk.
My problem is that the output file only contains spaces (the file size
is excatly what it should be but no text only black spaces).
Does anyone know why spaces appear instead of chars ?
this is the code for excel but the same happens with mhtml:
Dim deviceInfo, format As String
format = "EXCEL"
deviceInfo = String.Format("<DeviceInfo><OutputFormat>{0}</OutputFormat></DeviceInfo>",
format)
' Render report
m_files = notification.Report.Render(format, deviceInfo)
Dim fileName As String
fileName = "C:\" & m_files(0).FileName & ".xls"
Dim results(CInt(m_files(0).Data.Length)) As Byte
m_files(0).Data.Read(results, 0, CInt(m_files(0).Data.Length))
Dim _filestream As System.IO.FileStream = System.IO.File.OpenWrite(fileName)
_filestream.Write(results, 0, CInt(m_files(0).Data.Length))
_filestream.Flush()
_filestream.Close()You need to take the encoding of the stream into account. Use a stream
reader to read the contents passing in the encoding of the stream, and then
use a stream writer to write to the filestream, also passing in the
encoding.
--
-Daniel
This posting is provided "AS IS" with no warranties, and confers no rights.
"kman" <kamara1@.yahoo.com> wrote in message
news:1106326857.837797.301490@.z14g2000cwz.googlegroups.com...
> Hi,
> I'm writing a custom delivery extension that saves the rendered report
> to the disk.
> My problem is that the output file only contains spaces (the file size
> is excatly what it should be but no text only black spaces).
> Does anyone know why spaces appear instead of chars ?
> this is the code for excel but the same happens with mhtml:
> Dim deviceInfo, format As String
> format = "EXCEL"
> deviceInfo => String.Format("<DeviceInfo><OutputFormat>{0}</OutputFormat></DeviceInfo>",
> format)
> ' Render report
> m_files = notification.Report.Render(format, deviceInfo)
> Dim fileName As String
> fileName = "C:\" & m_files(0).FileName & ".xls"
> Dim results(CInt(m_files(0).Data.Length)) As Byte
> m_files(0).Data.Read(results, 0, CInt(m_files(0).Data.Length))
> Dim _filestream As System.IO.FileStream => System.IO.File.OpenWrite(fileName)
> _filestream.Write(results, 0, CInt(m_files(0).Data.Length))
> _filestream.Flush()
> _filestream.Close()
>|||Thanks,
I tried what you've suggested but i think i'm doing something wrong
because now i'm getting a zero byte file.
can you provide the code for that?
here's the code i added:
Dim encode As Encoding = m_files(0).Encoding
Dim _readStream As New StreamReader(m_files(0).Data, encode)
Dim _filestream As New System.IO.FileStream(fileName,
FileMode.OpenOrCreate)
Dim _writeStream As New StreamWriter(_filestream, encode)
_writeStream.Write(_readStream.ReadToEnd)
_writeStream.Close()
_readStream.Close()
_FileStream.Close()|||Daniel, somebody,
Please help ...|||You're correct - for excel there's no encoding. I tried the mhtml
format which has ASCIIEncoding.
I'm only sending the format in the device info:
String.Format("<DeviceInfo><OutputFormat>{0}</OutputFormat></DeviceInfo>",format)
I'm not sure what you mean to pass via url, i've tried to export the
report from the report manager and it works fine.
Can you post how to read it like you do ?|||Try not passing in this device info and instead pass the format in on the
render call only.
--
-Daniel
This posting is provided "AS IS" with no warranties, and confers no rights.
"kman" <kamara1@.yahoo.com> wrote in message
news:1106853884.827838.300370@.z14g2000cwz.googlegroups.com...
> You're correct - for excel there's no encoding. I tried the mhtml
> format which has ASCIIEncoding.
> I'm only sending the format in the device info:
> String.Format("<DeviceInfo><OutputFormat>{0}</OutputFormat></DeviceInfo>",format)
> I'm not sure what you mean to pass via url, i've tried to export the
> report from the report manager and it works fine.
> Can you post how to read it like you do ?
>|||i tried - notification.Report.Render(format, Nothing), but still
there's a black file.
i checked the findrendersave sample and it works fine there but i can't
use the render method directly from the web service because i need the
subscription info (parameters ...)
any ideas ?|||I'm sorry to say, I don't see what the problem is. I can't see anything
wrong with what you are doing. It should work.
--
-Daniel
This posting is provided "AS IS" with no warranties, and confers no rights.
"kman" <kamara1@.yahoo.com> wrote in message
news:1106909217.659089.277880@.z14g2000cwz.googlegroups.com...
>i tried - notification.Report.Render(format, Nothing), but still
> there's a black file.
> i checked the findrendersave sample and it works fine there but i can't
> use the render method directly from the web service because i need the
> subscription info (parameters ...)
> any ideas ?
>|||Hi,
Solved it. It wasn't the encoding after all but the position on the
data stream.
I added this line and it solved it:
_renderedOutputFile.Data.Seek(CType(0, Long),
System.IO.SeekOrigin.Begin)
Thanks for your help.
This is the complete code for saving the file (works for excel, mhtml
and pdf):
m_files = notification.Report.Render(format, Nothing)
Dim _fileStream As System.IO.FileStream = Nothing
Dim _renderedOutputFile As RenderedOutputFile
_renderedOutputFile = m_files(0)
Dim fileName As String = "C:\" & _renderedOutputFile.FileName.Trim &
"." & _renderedOutputFile.Extension.Trim
_fileStream = New System.IO.FileStream(fileName, FileMode.OpenOrCreate,
FileAccess.Write)
_renderedOutputFile.Data.Seek(CType(0, Long),
System.IO.SeekOrigin.Begin)
Dim arr(CInt(_renderedOutputFile.Data.Length)) As Byte
_renderedOutputFile.Data.Read(arr, 0,
CInt(_renderedOutputFile.Data.Length))
_fileStream.Write(arr, 0, CInt(_renderedOutputFile.Data.Length))
_fileStream.Close()
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment