Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Is it possible to from my ASCX usercontrol to write to a text file either on the file system or in a sharepoint list? I tried using a streamwriter but I always get that it cant find the file Ive created.

share|improve this question
    
definitely possible...can you expand on the problem and/or post your code because I'm not getting the correlation between writing out a file with a streamwriter and "I always get that it cant find the file I've created". Are you saying that you're able to create the file, but it says it can't find it once you try to write to it? either way, posting the snippet of code you're using to create/write might be helpful. –  Rob D'Oria Aug 12 '11 at 15:00
    
@Rob I guess I just dont know where to put the file, and how to reference the file when I am using the StreamWriter –  atrljoe Aug 12 '11 at 15:27
    
for starters, the default behavior of StreamWriter is to create the file if it doesn't exist assuming you're using the constructor that takes the path anyway. It's probably helpful to know the purpose of the file to give you a better recommendation on where it should go. –  Rob D'Oria Aug 12 '11 at 15:37
add comment

1 Answer 1

up vote 2 down vote accepted

Writing to the file system is very risky if you are in a load balanced environment as there is no guarantee that the code will be executed on the same server that wrote the file in the first place. However, even if you are on a single server environment, you will still hit deadlock/overwrite/permissions issues if two people happen to be accessing pages that contain your control at the same time.

Factor in the myriad of potential file system security issues and writing to the file system is significantly more work than it is worth.

It would be better to use a SharePoint list for this as it resolves both of the above issues. The exact code to use to write to the list would vary depending on what you are writing to the list and how (i.e. writing a file to a doclib versus attaching a file to a standard list item) In either case, I am pretty sure that you can use the MemoryStream object in order to keep everything in memory while you are preparing it to be written.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.