Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesResponse.WriteFile problemResponse.WriteFile problem
Previous
 
Next
New Post
2/17/2011 3:56 AM
 
Thank you very much.

It seems like I have solved it, I'll post the two changes I made:

1- fiirst of all, I had to put the "Content-Length" header, but then I noticed a strange thing (at least for me)

I was doing things like this:

Dim content as string = "My dynamically generated content"
'In the module, I catch data from the database and write it into the string

Dim MemStream as new MemoryStream
Dim sw as new StreamWriter(MemStream)

sw.write(content)

Dim bytes() as byte = MemStream.GetBuffer()

but I noticed that bytes() doesn't contain all the content; thus, the generated file would look like "My dynamically generated con", as if the string was truncated.

2- To solve this, I changed the way I created my byte array this way (thanks to Kelly)

Dim utf8 as new UTF8Encoding()
Dim bytes() as byte = utf8.GetBytes(content)

and now everything is working fine.


Just to know, is there a reason why thw StreamWriter.write(string) works that way? I tried to look into msdn but I didn't see anithing about that.

Thanks to everyone for the help.

Regards,

Alberto
 
New Post
2/17/2011 3:28 PM
 
GetBuffer allocates blocks of data at a time(1024 I think it is). What may have been happening is when it allocated the last block of data, it didn't fill it up and left garbage space available. I don't know how the page html could have gotten in there but weird things can happen with memory allocated on the heap at the byte level.

After finding this post...
http://blogs.msdn.com/b/rnarayan/archive/2007/08/06/beware-of-memorystream-getbuffer-method.aspx
...it looks like others have had the same problem you did, and using the memstream like this is better:
byte[] bytArr = memStream.ToArray();
slPort.Write(bytArr, offset, bytArr.Length - offset);

There is always 10 ways to do something in programming so if you can't get one thing to work, google always has an alternative.
 
New Post
2/18/2011 5:15 AM
 
Thank you for the exlpanation and link.
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesResponse.WriteFile problemResponse.WriteFile problem


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out