Click here to Skip to main content
15,900,589 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have one query regarding one scenario i.e.

Architecture:

I had created one WCF service which is containing the logic for uploading, downloading and deleting the files from sharepoint. Now, this WCF is being called from windows service for every 30 seconds. This means that the process will run for every 30 second to upload, download and delete the files to and from Sharepoint. Please not that I had created three separate window service which are calling one WCF service.


Issue:

1) During uploading the files using window service, if some error is occurring while uploading one file than service is throwing exception and it is not going to next file to upload it. This is a roadblock for this service as I want the service to continue the uploading of other files which are not causing exceptions.

Regards,
Abhishek Pareek
Posted
Updated 14-Dec-10 20:31pm
v2
Comments
Abdul Quader Mamun 15-Dec-10 2:31am    
Spelling check.
Thomas Krojer 15-Dec-10 2:55am    
Where is the problem? Try/Catch block?

Hi Abhishek,

Mark the state of file in db or in collection like tranfered, error ,ready etc.
If any error occur in one file handle using faultcontract and try/catch block WCF Error Handling and Fault Conversion[^].
Again start transfer those file which are in ready state.
 
Share this answer
 
Hi Vivek,

My problem is that my window service is halting up when it is getting error during uploading of files and it is not going to process next file. I would like to do make amendments in such a way that if window service is experience some error like related to file size etc. than it should look for next file to upload.

Please note that I had made this window and WCF service for upload, download and delete thousands of files in a mintue. So if my window sevice halting at second file than it will be always stuck at second only until I resolved the issue. I would like to amend the functionality in such a ways that if error occurs at second file it should go for next file ownwards.

Regards,
Abhishek pareek
 
Share this answer
 
You could catch the exception which you know are safe to proceed with and not throw them, like below:


MIDL
try
{
    //do stuff
}
catch (System.IO.FileNotFoundException)
{
    //log exception
}
catch (Exception ex)
{
    throw;
}
 
Share this answer
 
Hello,

Please find the code below:

This code is using a service to get all the sharepoint users and than depending upon the name of user it is searching the directory whose name is similar to sharepoint user name. Eralier problem was if my code is not able to find out the directory on the system than the service was stopping at that point therefore I put a check whether directory exist. If directory exists than coppy all files from that directory and upload it to sharepoint.
i.e
if (dire.Exists) than do the processing

Now the problem has just begun as we know this error can occur therefore I had make a check but some errors might occur like file name is exceeding than at time also my service will stop so I want that my service will not look for that file and should go to fecth next file.

Please find the code below and suggest some solution.


try
{
sp2.Service oUploader = new global::KwikWSSUploader.sp2.Service();
oUploader.Url = GetConfigValue("WCFServiceURL");
oUploader.PreAuthenticate = true;
oUploader.Credentials = CredentialCache.DefaultCredentials;
string[] UsrList;
UsrList = GetAllSharepointUsers(oUploader);
for (int i = 0; i < UsrList.Length; i++)
{
UserName = UsrList.GetValue(i).ToString();
iStartIndex = UserName.LastIndexOf("\\");
string folderName = UserName.Substring(iStartIndex + 1);
dirname = GetConfigValue("SourceFolderDrive") + folderName;
DirectoryInfo dire = new DirectoryInfo(dirname);
if (dire.Exists)
{
bool permDir = HasPermissionOnDir(dirname);
if (permDir)
{
FileInfo[] fyles = dire.GetFiles("*.*");
string strPath;
string strFile;
string strDestination = "";
bool Overwrite = false;
Overwrite = bool.Parse(GetConfigValue("Overwrite"));
foreach (FileInfo f in fyles)
{
strPath = dirname + "\\" + f.Name;
strFile = strPath.Substring(strPath.LastIndexOf("\\") + 1);
strDestination = GetConfigValue("SPLibPath") + folderName;
FileStream fStream = new FileStream(strPath, System.IO.FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
byte[] binFile = new byte[(int)fStream.Length];
fStream.Read(binFile, 0, (int)fStream.Length);
fStream.Close();
string str = oUploader.UploadDocument(strFile, binFile, strDestination, GetConfigValue("Overwrite"));

}
if (fyles.GetUpperBound(0) != -1)
{
eventLog1.WriteEntry("Files successfully uploaded to " + strDestination);
}
sDelete = GetConfigValue("DeleteSystemFolderFiles"); ;
if (sDelete == "1")
{
foreach (FileInfo fi in fyles)
{
fi.Delete();
}
}
}
}
}
}
catch (Exception ex)
{
eventLog1.WriteEntry(ex.Source + " - " + ex.Message + " - " + ex.InnerException + " - " + ex.StackTrace);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900