A representative of Christopher Little, agent for Harry Potter author JK Rowling, says fan-written fiction is like "flattery" when done right:
...is fan fiction a legitimate literary genre or is it just plagiarism? Well, it is not a prerequisite, but many writers add a disclaimer before posting their stories on mailing lists. They don't own the characters, nor the plot.
Yet JK Rowling's literary agent, for instance, has asked some internet service providers and website operators to remove any pornographic fanfic based on Harry Potter, simply because children would be able to access it. But this is an issue about internet policing rather than the act of writing itself. In fact, a representative for Rowling's agent states that "the general feeling is one of flattery" - as long as it's clear that the author isn't JK Rowling.
Original link includes this story at bottom.