Visual Studio 2010을 사용하는 C# 프로그램에서 SharePoint 문서 라이브러리에 파일을 업로드하는 중 문제가 발생했습니다. 분명히 프로세스 "sqlservr.exe * 32 "는 1GB 이상의 메모리와 같습니다. 파일을 업로드하기 위해 먼저 파일의 바이트를 byte [] 배열로 읽습니다. 그런 다음 배열을 파일로 문서 라이브러리에 업로드하십시오. 각 파일을 업로드하기 전에 메모리를 지울 수있는 방법이 필요합니다.C# 프로세스를 종료하고 시작하는 방법
프로그램은 디렉토리에서 반복되는 루프에서 파일을 업로드합니다. 바이트 배열의 메모리를 지우는 방법이 있습니까?
실제로 "sqlservr.exe * 32"프로세스를 다시 시작하여 메모리를 확보 할 수있는 방법이 있습니까?
이것은 내가 업로드하는 데 사용하는 코드입니다 :
을 내가 웹 사이트에 표시되는 오류 메시지는 (문제는 나는 그것이 메모리 밖으로에서도 때로는 다른 파일을 실행 생각하는 발생할 때 메시지) : 'Test Library/myfolder/file.txt'URL이 잘못되었습니다. 존재하지 않는 파일 또는 폴더를 참조하거나 현재 웹에없는 유효한 파일 또는 폴더를 참조 할 수 있습니다.
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 a file
if (File1.PostedFile == null)
{
return;
}
try
{
// Get the directories in the 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 the memory
GC.Collect();
// For each directory in the main path
for (i = 0; i < array1.Length; i++)
{
// Get directory name
dir_name = Path.GetFileName(array1[i]);
// Skip this file
if (dir_name == "viDesktop_files" || i < start_id || i >= end_id)
{
continue;
}
// Get the site
SPSite site = new Microsoft.SharePoint.SPSite("http://mysite/");
// Turn security off
Microsoft.SharePoint.Administration.SPWebApplication webApp = site.WebApplication;
webApp.FormDigestSettings.Enabled = false;
// Get site root
SPWeb spWeb = site.RootWeb;
// Get the specified list/library from the site root
SPList docLib = spWeb.Lists["Test Library"];
// Get all files in the directory
temp = Directory.GetFiles(array1[i]);
// Create a folder in the list/library
SPListItem folder = docLib.Folders.Add(docLib.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, dir_name);
// Activate the newly created folder
folder.Update();
// For each file in the directory
for (j = 0; j < temp.Length; j++)
{
// Get file name
file_name = Path.GetFileName(temp[j]);
// If the file is a .mht file
if (file_name.EndsWith(".mht"))
{
// Read the contents of the uploaded file into the variable 'contents'
contents = File.ReadAllBytes(temp[j]);
// Add the file with the specified filename in the folder
SPFile file = folder.Folder.Files.Add(file_name, contents);
// Activate the file
file.Update();
}
}
// Turn security on
webApp.FormDigestSettings.Enabled = true;
// Close the site
site.Close();
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}
** ** "sqlservr.exe * 32"프로세스 이름을 지정 하시겠습니까? 왜 다른 프로세스의 메모리 사용이 프로세스에 영향을 줄 것이라고 기대합니까? –
@Alexei 안돼. 셰어 포인트와 SQL 서버 (32 비트)입니다. 나는 두 번째 질문에 대답 할 수 없다. –
"우리의 메모리를 실행 중"- 메모리가 부족합니까? 프로세스에 OOM 예외가 발생합니까? OS가 불평? 작업 관리자의 숫자만으로도 불행하게 만들 수 있습니까? –