sql - c# how to terminate and start a process -


in c# program (using visual studio 2010), uploading files sharepoint document library, problem running our of memory, apparently process "sqlservr.exe*32" on 1 gb of memory. upload file, first read bytes of file byte[] array. upload array file document library. need way clear memory before uploading each file.

the program uploads files in loop iterates in directory. there way clear memory of byte[] array?

actually there way can restart process "sqlservr.exe*32" free memory?

this code use upload:

and error message see on website (when problem occurs, think running out of memory, different files in message): url 'test library/myfolder/file.txt' invalid. may refer nonexistent file or folder, or refer valid file or folder not in current web.

using system; using microsoft.sharepoint; using microsoft.sharepoint.webcontrols; using system.io; using microsoft.sharepoint;  namespace customapplicationpage.layouts.customapplicationpage {     public partial class customapplicationpage : layoutspagebase     {         protected void page_load(object sender, eventargs e)         {              // check if user posted file             if (file1.postedfile == null)             {                 return;             }              try             {                 // directories in path                 string[] array1 = directory.getdirectories("c:\\myfolder\\");                  // declare variables                 string[] temp;                 byte[] contents;                 string dir_name;                 string file_name;                 int i, j;                 int chunk_size = 5;                 int chunk_index = 0;                 int start_id = chunk_size * chunk_index;                   int end_id = 1 + (chunk_size * (chunk_index+1));                  // free memory                 gc.collect();                  // each directory in main path                 (i = 0; < array1.length; i++)                 {                     // directory name                     dir_name = path.getfilename(array1[i]);                      // skip file                     if (dir_name == "videsktop_files" || < start_id || >= end_id)                     {                         continue;                     }                      // site                     spsite site = new microsoft.sharepoint.spsite("http://mysite/");                      // turn security off                     microsoft.sharepoint.administration.spwebapplication webapp = site.webapplication;                     webapp.formdigestsettings.enabled = false;                      // site root                     spweb spweb = site.rootweb;                      // specified list/library site root                     splist doclib = spweb.lists["test library"];                      // files in directory                     temp = directory.getfiles(array1[i]);                      // create folder in list/library                     splistitem folder = doclib.folders.add(doclib.rootfolder.serverrelativeurl, spfilesystemobjecttype.folder, dir_name);                      // activate newly created folder                     folder.update();                      // each file in directory                     (j = 0; j < temp.length; j++)                     {                         // file name                         file_name = path.getfilename(temp[j]);                          // if file .mht file                         if (file_name.endswith(".mht"))                         {                             // read contents of uploaded file variable 'contents'                             contents = file.readallbytes(temp[j]);                              // add file specified filename in folder                             spfile file = folder.folder.files.add(file_name, contents);                              // activate file                             file.update();                         }                     }                      // turn security on                     webapp.formdigestsettings.enabled = true;                      // close site                     site.close();                 }             }             catch (exception ex)             {                 throw ex;             }         }     } } 

free results , close connection... can restart process there larger problem... try using linq , datacontext

http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.aspx

if believe have setup correctly attempt use sql profiler , see whats going on @ db level...

http://msdn.microsoft.com/en-us/library/ms181091.aspx


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -