Cannot access a closed file error on adding a file to a library

I am trying to copy the attachments from a list to a document library. When I try to write into a document library, occasionally I am getting following error "The remote server returned an error: (500) Internal Server Error.  Cannot access
a closed file.  Cannot access a closed file.  "
Any ideas on what is causing the problem. The code is specified below, The error message is specified after the code. Can you please let me know if I am missing anything. I cant find anything wrong in the code or in the library. The code is running as WCF
Service and the call to process this is made from Infopath form.
try
SPSecurity.RunWithElevatedPrivileges(delegate()
string siteURL = "Site URL";
using (SPSite site = new SPSite(siteURL))
SPWeb oWeb = site.OpenWeb();
SPList oList = oWeb.Lists["List Name"];
SPList docDestination = oWeb.Lists["Destination Library on same site"];
SPFolder fldRoot = oWeb.Folders["Destination Library on same site"];
SPFileCollection flColl = null;
SPQuery oQuery = new SPQuery();
oQuery.Query = "<Where><Eq>" + "<FieldRef Name=\"ID\"/><Value Type=\"Number\">" + RequestID + "</Value></Eq></Where>";
SPListItemCollection oItems = oList.GetItems(oQuery);
foreach (SPListItem lstItem in oItems)
if (lstItem["ID"].ToString() == RequestID)
if (lstItem.Attachments != null && lstItem.Attachments.Count > 0)
foreach (String strName in lstItem.Attachments)
flColl = fldRoot.Files;
SPListItem listtem = docDestination.Items.Add();
SPFile FileCopy = lstItem.ParentList.ParentWeb.GetFile(lstItem.Attachments.UrlPrefix + strName);
SPQuery oQueryDest = new SPQuery();
oQueryDest.Query = "<Where><Eq>" + "<FieldRef Name=\"Name\"/><Value Type=\"Text\">" + FileCopy.Name + "</Value></Eq></Where>";
SPListItemCollection collListItems = docDestination.GetItems(oQuery);
string destFile = flColl.Folder.Url + "/" + FileCopy.Name ;
if (collListItems.Count > 0)
String strFileNamePrfix = FileCopy.Name.Substring(0, FileCopy.Name.Length - 3);
strFileNamePrfix = strFileNamePrfix + "_" + collListItems.Count.ToString();
strFileNamePrfix = strFileNamePrfix + FileCopy.Name.Substring(FileCopy.Name.Length - 3,3);
destFile = flColl.Folder.Url + "/" + strFileNamePrfix;
byte[] fileData = FileCopy.OpenBinary();
Trace.WriteLine("Board Services dest file" + destFile + " Count = " + collListItems.Count.ToString());
SPFile flAdded = flColl.Add(destFile, fileData,true);
SPListItem item = flAdded.Item;
flAdded.Item.Update();
catch (Exception ex)
string strLogEntry = ex.Message.ToString() + ex.StackTrace.ToString();
finally
Form submission failed. (User: xxxxx, Form Name: Template, IP: , Request: http://Site Url/Lists/List name/Task/editifs.aspx?List=e6647e38-cb01-46b3-8bee-308357045532&ID=116&Source=http://Site URL/Lists/List Name/AllItems.aspx?View={CB9F3C2B-49DF-4D75-9720-1E7E000FD229}&FilterField1=Status&FilterValue1=Completed&IsDlg=1&Web=706d51c9-e509-40f3-884a-7d40e126ff14,
Form ID: urn:schemas-microsoft-com:office:infopath:list:-AutoGen-2013-12-06T16:11:54:747Z, Type: DataAdapterException, Exception Message: The remote server returned an error: (500) Internal Server Error.  Cannot access a closed file.  Cannot
access a closed file.  
 at System.IO.FileStream.Write(Byte[] array, Int32 offset, Int32 count)    
The remote server returned an error: (500) Internal Server Error.)

Hi Dimitri,
Thank you, I tried increasing the timeout on web.config file of the wCF service and reloaded the config file.
<httpRuntime executionTimeout="90" maxRequestLength="20000" useFullyQualifiedRedirectUrl="false" requestLengthDiskThreshold="8192"/>
As the error
Form submission failed. (User: , Form Name: Template, IP: , Request: http://site /editifs.aspx?List=e6647e38-cb01-46b3-8bee-308357045532&ID=102&Source=http://site List/AllItems.aspx?View={cb9f3c2b-49df-4d75-9720-1e7e000fd229}&SortField=Status&SortDir=Asc&IsDlg=1&Web=706d51c9-e509-40f3-884a-7d40e126ff14#,
Form ID: urn:schemas-microsoft-com:office:infopath:list:-AutoGen-2013-12-06T16:11:54:747Z, Type: DataAdapterException, Exception Message: The remote server returned an error: (500) Internal Server Error.  Cannot access a closed file.  Cannot access
a closed file.  
 at System.IO.FileStream.Write(Byte[] array, Int32 offset, Int32 count)    
is happening at following line
SPFile flAdded = flColl.Add(destFile, fileData,attachmentPropertiesHashTable ,true);
I only modified the timeout on the wcf service.
I dont think I need to change the timeout on the Webapplication which has this site?
Regards
Nate

Similar Messages

  • Moved iTunes library to an ext hard drive to make space on my int drive... Followed steps from apple.  Now I cannot access my music... It says: "File could not be used because the original file cannot be found.  Would you like to locate it?"

    Moved iTunes library to an ext hard drive to make space on my int drive... Followed steps from apple.  Now I cannot access my music... It says: "File could not be used because the original file cannot be found.  Would you like to locate it?"
    I moved my iTunes library to my external hard drive some time ago and I followed the directions listed here on the apple support page.  It did copy my library and now is on my hard drive... I can open iTunes and use it to sync all of my devices but I would like to play my music... I can see all of my music files but can not play them if I click on an album or song it says the following:  "(file name) could not be used because the original file cannot be found.  Would you like to locate it?"  I click locate but do not know where to go from there?  I need a way to access all files and not to hunt down one at a time on my hard drive... I am pretty sure I deleted the original library to make space on my internal drive which was the reason for moving it.  I have tried and tried to fix it and do not have a lot of time to do so with a one and two year old at my house who do not like it whenI sit down at my computer.  What to do???  Any help is much appreciated!!!

    See Make a split library portable. Move all of the bits of the library together in the the correct shape and it should work. Or undo exactly what you did and then start over.
    If you're a former Windows user don't try merging two folders together that have the same name by dropping one into the same folders as the other, as that goes badly on a Mac.
    tt2

  • Create database fails with error ORA-01505: error in adding log files

    hi all,
    hope someone can help me out, I'm trying to create a database using a SQL script, the content of the script is:
    create database testora
    user sys identified by oracle
    user system identified by oracle
    logfile group 1 ('/u01/app/oracle/oradata/testora/redo01a.log', '/u02/app/oracle/oradata/testora/redo01b.log') size 100m blocksize 512 reuse,
         group 2 ('/u01/app/oracle/oradata/testora/redo02a.log', '/u02/app/oracle/oradata/testora/redo02b.log') size 100m blocksize 512 reuse,
         group 3 ('/u01/app/oracle/oradata/testora/redo03a.log', '/u02/app/oracle/oradata/testora/redo03b.log') size 100m blocksize 512 reuse,
    maxlogfiles 5
    maxlogmembers 5
    maxdatafiles 100
    character set US7ASCII
    national character set AL16UTF16
    extent management local
    datafile '/u01/app/oracle/oradata/testora/system01.dbf' size 400m reuse
    sysaux datafile '/u01/app/oracle/oradata/testora/sysaux01.dbf' size 400m reuse
    default tablespace users
         datafile '/u02/app/oracle/oradata/testora/users01.dbf' size 500m reuse autoextend on maxsize unlimited
    default temporary tablespace tempts1
         tempfile '/u01/app/oracle/oradata/testora/temp01.dbf' size 20m reuse autoextend on maxsize 4g
    undo tablespace undotbs1
         datafile '/u01/app/oracle/oradata/testora/undotbs01.dbf' size 200m reuse autoextend on maxsize unlimited
    It fails in creating the database with the following output:
    SQL> @/home/oracle/Oracle_Scripts/testora_db_script.sql
    create database testora
    ERROR at line 1:
    ORA-01092: ORACLE instance terminated. Disconnection forced
    ORA-01501: CREATE DATABASE failed
    ORA-01505: error in adding log files
    ORA-01184: logfile group 1 already exists
    Process ID: 3486
    Session ID: 1 Serial number: 3

    sorry to revive this thread but i have one more issue with this. I created a database with DBCA insetead of CREATE DATABASE command and selected option for Fast Recovery Area space. This automatically set initialization parameter db_recovery_file_dest and db_recovery_file_dest_size, but did not create a OMF redo log group, but instead created three redo log groups with 1 member each.
    select * from v$logfile returns:
    1          ONLINE     /u01/app/oracle/oradata/testdb2/redo01.log     NO
    2          ONLINE     /u01/app/oracle/oradata/testdb2/redo02.log     NO
    3          ONLINE     /u01/app/oracle/oradata/testdb2/redo03.log     NO
    Any idea why if creating a database with create database command and specifying db_recovery_file_dest creates an OMF redo log group and with DBCA it doesn't?

  • Getting Error in CMC - source file error. [No such file or directory]: [CrystalEnterprise.Smtp]

    Dear All,
    I am able to schedule the Crystal report successfully means mail gets auto triggered as we set in SCHEDULE option. But when we tried to use the notification option we get the status as FAILED. nd in details we get "source file error. [No such file or directory]: [CrystalEnterprise.Smtp]".
    But still a mail gets triggred and each and every person will get mail. but the issue is notification will not work properly and no notification mail. And the status is despayed as FAILED with "source file error. [No such file or directory]: [CrystalEnterprise.Smtp]" this message.
    Regards,
    Rohan Ghadi

    Do you have multiple job servers in your environment? Did all the Job servers configured SMTP settings?

  • I do not have Microsoft office and to know if I can still open docx files - error message reads corrupt files.  Is there a reliable converter out there?

    I do not have Microsoft office and want to know if I can still open docx files - error message reads corrupt files.  Is there a reliable converter out there?  I am a new mac user.

    Install the free LibreOffice and save a bundle not having to pay MS. http://www.libreoffice.org/

  • Cannot access a shared folder Error code: 0x80070035

    Hello Experts,
    I have been working on this issue for like three days without a solution. I am truly desperate.
    My company just purchased a new Cloud Server that we will use as our development environment for a software project. In order for all the developers (which are all over the US) to access the development environment, we need to have a few shared folders on
    that new server.
    As soon as we got the server I did the following:
    1) Installed Active Directory
    2) Created a directory and made it shared - yes IT IS shared.
    3) I created a few new users on the new active directory domain
    THE PROBLEM:
    I can't access the shared directory.
    Other developers have been successful in connecting to the shared folder (so the share is working) - all except me.
    when I open explorer and type \\IPADDRESS\SHAREDFOLDER instead I get this error (I am not even asked for credentials)
    Network Error
    Windows cannot access \\IPADDRESS\SHAREDFOLDER
    Error code: 0x80070035
    The network path was not found.
    Things I have already tried:
    a) Enable NetBIOS over TCP/IP - on all adapters - still did not help
    b) Disable IPv6 - I am not sure how to check if it truly disabled
    c) Turned off all firewalls - did not help
    d) Mapping a Drive using different credentials - I just get asked for credentials over and over
    e) Ping - yes I can see the server
    f) My credentials are correct because I can Remote Desktop with the credentials with no problem ( I am administrator)
    My Machine:
    Brand New Asus G Series
    Windows 7 Home Edition
    Any ideas?
    Sorcerdon

    In my case it was that the OU that my system was in did not have firewall rules for network file and printer sharing enabled. I enabled all of the rules for Domain policy and that fixed it.
    I noticed a lot of comments about turning off the firewall not working. I can't be 100% sure, but in my experience with Server 2008 and Windows 7, if you want to configure a service that uses the network the base filter engine and the firewall HAVE to be
    turned on while you configure. You can turn the firewall off after configuration, but they have to be active during configuration.
    Good luck!

  • Cannot Access External Data - Dash error

    I'm facing some problems to access a Dashboard. This problem is intermittent and ,at the same time, one user can access and another get the error message "Cannot Access External Data ; Value of from=GetReportBlock_Sales_Dashboard_Gap_Analysis entered is incorrect.".
    No changes were made on this Dashboard and since middle of last year everything runs Ok.
    This dashborad uses QaaWs.
    The BW query runs OK and no incorrect data was found.
    All caches were cleaned.
    Could anyone suggest what should I do?
    Tks!

    Hi
    I would suggest to monitor the system when the error happens
    1. http traces as per SAP note 1231878 - How to trace a SWF file's data connectivity inside Internet Explor
    2. webi processing server traces on your BOE server as per SAP note 1335757 - Enabling and disabling tracing in XI 3.1 for specific services without requiring a restart
    3. QAAWS traces as per SAP note 1199027 - How to turn on log4j logging for Query As A Web Service (QAAWS) / Live Office
    Regards
    F,

  • I cannot access safari. Get error message: deals with system configuration. Tried basic reinstalling of OSx

    Suddenly I am unable to access Safari when I click the icon. Read book and followed basic troubleshooting: reinstall Mac OS X & applications. Icon there but still cannot access. Error code reads: cannot be openned b/c problem; deals w/system config. System still under warranty. What am I doing wrong? Any thoughts out there?
    angelia m

    Suddenly I am unable to access Safari when I click the icon. Read book and followed basic troubleshooting: reinstall Mac OS X & applications. Icon there but still cannot access. Error code reads: cannot be openned b/c problem; deals w/system config. System still under warranty. What am I doing wrong? Any thoughts out there?
    angelia m

  • Cannot backup in PSE 9  'error encountered while writing file(s)'.

    Cannot backup either full or incremental in PSE 9 'error encountered while writing file(s)'.
    I've not had any problem on this machine (MacbPro) to my ext hdrive previously, plenty of space.
    Any ideas?
    Doesn't look as if files are corrupted.

    Sorted! Faulty usb lead.

  • Cannot access itunes tells me error 7 windows error 1114?

    Cannot reinstal itunes. tells me error 7 windows error 1114

    Try the following user tip:
    Troubleshooting issues with iTunes for Windows updates

  • Corrupt file error while writting a file in compress mode

    Hello,
    I have a scenario where i am writting data in a file in appending mode with filter 'compress' addition using open dataset, on Al11 for the first set of records it works fine but if this file is accessed again for writting data in next select statement ( its between select endselect),the file is getting corrupted, if i try to open this file corrupt file error come. can someone help.
    Thanks and Regards,
    Gunjan

    Hi Gunjan,
    Unfortunately, you can't do in that way. The behaviour of that OPEN and FILTER 'compress' clause is to create a compacted file, to be read later, but it can be appended... all your writes go to a pipe and when you close the file this is sent to 'compress' program or other filter and than a compacted file is created.
    You can't go back and start inserting again after close it.
    Follow documentation:
    http://help.sap.com/abapdocu_70/en/ABAPOPEN_DATASET_OS_ADDITION.htm
    The addition FILTER must not be used together with the addition AT POSITION or for the access type FOR UPDATE.
    Regards, Fernando Da Ró

  • Unknown file error, not with reference files

    I get unknown file errors when trying to import quicktime movies (.mov) that are NOT reference files. I exported them using quicktime conversion and they take up several megabytes for about 10 seconds of video, and I even did cmd-j in quicktime to check. What else could be causing this? I have read write access too...
    Thanks, Zach

    What codec did you use when you exported the movies?

  • File error when importing .mp4 files

    Hi there,
    I have a problem concerning importing files.
    I had some .mkv files, which I converted to .mp4 files with just 1 audio track and no subtitles using Handbrake.
    Problem is, I can't import these files into Final Cut Pro 7.
    It gives the following error:
    "File error: 1 file(s) recognized, 0 access denied, 1 unknown."
    I have no problem importing .avi files, or .mp4 files that haven't been converted.
    Does anyone know what I should do? I don't know any other program to convert .mkv files, so basically, I'm bound to using Handbrake.
    Thanks in advance!!

    I didn't know Handbrake was such a bad tool.
    I never did much video-editing before, so I usually used iMovie, and the Handbrake-converted files worked fine with that.
    And I did what you said, I converted the video to .mov with MPEG Streamclip, using the mentioned presets, but now I have another problem.
    A 22 minute file, which was 360MB before converting, turned into a 6.2GB file after converting.
    Since I use videoclips from a TV Serie, which has over 60 episodes, this is going to cost a lot of space. Is there any way to reduce the filesize without destroying the video quality, or is there any, ANY, way to make FCP accept .mp4 files?
    I don't care if it slows down my Mac or anything, it's just that I know it's possible, with the 700MB file from one of my posts above.

  • Need help in  URI scheme is not ¨file¨  error in uploading .PDF file

    I am getting the URI scheme is not file error when I am uploadin a .PDF file
    I am using the following piece of code
    String lPathPrefix = "gopher://muceap10.muc.amadeus.net/User Step Folders/BPS_Files/Outlooksoft CPM/01 - Production Environment/01 - Documentation Library/01 - Documents/Daily_Checks/";String lPath = (lPathPrefix + doccolvalue).replace(" ", "%20");
    URI lURI = new URI(lPath);String lPathPrefix = "file://muceap10.muc.amadeus.net/User Step Folders/BPS_Files/Outlooksoft CPM/01 - Production Environment/01 - Documentation Library/01 - Documents/Daily_Checks/";
    String lPath = (lPathPrefix + doccolvalue).replace(" ", "%20");
    URI lURI = new URI(lPath);
    Can anyone please help me in solving this problem
    I will be very much greatful to you,
    Thankx.

    Did you get to resolve this error? We are also getting the same error and not able to figure out.
    Edited by: Joe A on Nov 10, 2008 5:09 PM

  • Unsupported file error when uploading video file to iTunes U

    I downloaded one of my video file and remove the track afterwards. However, when I trying to reload the video files back to the site again, I got "Unsupported File" error for some of them. My files are withing 50MB ~ 500 MB range, codec of H.264 and AAC.
    Any suggestions/

    Could someone please give some suggestions? I've been stuck with these "Unsupported File" for a week...

Maybe you are looking for

  • How to use a Template in reports as in Forms ?

    Goal: I need to use reuse a common code in all of my reports. Current scenario: I need to display Report title, database name and report REP file name in the header of each report. So if I change at one place it should be reflected at all he places I

  • Problems installing Photoshop CS2 on iMac

    I have my brand new iMac 20" Intel Core Duo, and I have recently purchased Photoshop CS2 and I can not get it to install. I saw in some places about the SU 2006-003 patch, but I have not installed that. I also saw about VC2 in the startup items, but

  • Installer Crashes on Run

    Windows 7 64 Bit. I had adobe air installed for Leauge of Legends. It stopped working and I tried fixing the game client. Uninstalled and then re-installed the game but when I try to re-install adobe air, the installer crashes without showing any win

  • My iPod Classic 6th gen won't charge on wall charger and it's not even recognized on iMac or Windows

    Hi! I hope someone can help me with this. I have had this 160 Gigs iPod Classic for a couple of years now and never had this problem before. I have tried to connect my iPod with several cables (which work fine with my iPod Touch and iPhone, by the wa

  • Indexes failed.

    In my process chain at initial fill BIA indexes level,iam getting the following errors: creation of index terminated an index already exists with the same name ; index = p creation of BIA index xxxx terminated for infocube xxxx  terminated during act