.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Folder's file count getting mismatched

Posted By:      Posted Date: September 21, 2010    Points: 0   Category :SharePoint


I have a folder, which contains sub folders. For example: Doc is the root folder. Inside it has 2 sub folders named Doc1 and Doc2.

Doc1 contains 2 sub folders - fol1 and fol2.

"fol2" folder does not contain any files, where as "foc1" has a file in it. I am trying to get the count of files modified in last 30 days. Against each of the sub folders,and the corresponding parent folder i want to show the count of modified items. I am getting the sub folders count, but that count is not getting updated to the parent folder.

I am missing a small part of updation, but not sure where it is. This is the code i have used:


public static void GetOpenItems()
SPFolder folder = list.RootFolder;
int mouas = 0;

if (folder != null && folder.Name.CompareTo("Forms") != 0)
//Get Individual Folder Total
 foreach (SPFolder subFolder in folder.SubFolders)
  if (subFolder.Name.CompareTo("Forms") != 0)
  mouas = CountFilesInFolder(subFolder, System.DateTime.Now.AddDays(-30));
  subFolder.Item["Files_Count"] = mouas;

static int CountFilesInFolder(SPFolder folder, DateTime startDate)

View Complete Post

More Related Resource Links

Getting file count on folder basis

Hi, I am getting the count of items modified in last 30 days. But I would like to get it a folder and sub folder basis. How to achieve this. [CODE]  int coa = 0; foreach (SPListItem item in AuditList.Items) {    DateTime CurDate = DateTime.Now;    DateTime gesDate = item.File.TimeLastModified;    TimeSpan t1 = CurDate - gesDate  ;    if (t1.TotalDays <= 30)   {         coa++;    } } Console.WriteLine("count is" + coa); [/CODE] How to achieve the above . Thank you

Count words in the ascx file



I have 163 .resx files. I want to count the words in these files, because my want to translate the sentences (my task is the localisation).

Now I'm opening each file in Ms Visual Studio and I count words manually. How can I count words in all files? And the second question: can I use a program what grab strings from .resx into an editor where I can translate them and save bacn into .resx files? Or must open the files one by one and edit the text fields manually?

Thanks for helping, unfortunately I'm not a programmer.

Programmatically delete a .webpart file from wpcatalogs folder from an IIS website


We are using a third party wsp in our solution which directly adds the web parts into the web application store rather than the web part gallery(References to them are present in IIS site's wpcatalog directory). We want to remove these web part files so that the users will not be able to add these web parts to pages directly. Or any other modification so that users will not be able to add these directly. Is there a way we can do this programmatically?

Method/Way to know whether a input path of FilesSystem contains any Child file/folder or not

Hi,I am looking for a Method/Way to know whether a input path of FilesSystem contains any Child file/folder or not. To know it currently I am using "Directory.GetFileSystemEntries(Path).Count" and checking if count > 0 then returning True else False. For this first method calculates all the files and folder and then return status to me but I want to exit out as soon as my method gets first element(file/folder) in specified path. Because above method is timing out when my input path contains more than 1 million files. I just need to check whether input folder path contains any child file/folder or not. I have tried to use Win32 API also but on ther server it is crashing so I donot want to use that solution. In .NET any method or way is present to know it. Please suggest me.

Web Folder problem : This file cannot be saved to this location because there is no connection to th

When I check out a Word 2007 document from a list, I cannot save it back to the server.  I get:   This file cannot be saved to this location because there is no connection to the server.  Check your network connection and try again.   I am using a Virtual Machine (Virtual PC).  I have the Microsoft Loopback adapter installed.    The server has a static IP address and is a domain controller. I am able to access the web folder through Windows Explorer.   How do I set up Office, Sharepoint and Webdav so that I can check files out of sharepoint and save them back, on a virtual machine?

using application configuration file in AppData special folder

Hi! So I understand it is a best practice to save the application configuration files under the AppData folder, rather than in Program Files, since UAC will restrict write acces to the Program Files folder, which is fine. Now, saving the configuration file to another location is no problem, using the SaveAs method. However, when I load the application, I expect some settings to be read. From what I know, this is done either using direct calls to the ConfigurationManager class, either initializing a Configuration object. For the first case, a example is this: if (ConfigurationManager.AppSettings["Title"] != null) { this.Title = ConfigurationManager.AppSettings["Title"]; titleTextBox.Text = ConfigurationManager.AppSettings["Title"]; } For the second case, I would use it like this: Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None); string setting = config.AppSettings.Settings["Title"].Value.ToString(); So, if the application runs in the Program Files folder, an exception is thrown when I save the file. However, if I save the file using SaveAs and save it to AppData folder, obviously, when loading, the settings are not loaded from the AppData folder, but from the configuration file existing in the Program Files folder. One way to solve

Saving Image File in a Folder on Sever from Client Machine using Sql Server

  Hi EveryOne... Can anyone help me Saving an Image file in a Server folder from a client machine using Sql server 2005....   

specified file or folder name is too long

Hi, We have MOSS 2007 SP1 databases on SQL Server 2005 SP3. All are 64 bit. We are intermittingly seeing the below  message in ULS log.: 09/01/2010 07:07:16.34 w3wp.exe (0x14BC)                       0x0D14 Windows SharePoint Services   General                                       8kh7      High       The specified file or folder name is too long. The URL path for all files and folders must be 260 characters or less (and no more than 128 characters for any single file or folder name in the URL). Please type a shorter file or folder name   But I'm unable to find the root cause that is causing this issue. I want to find which particular document or process or url is  cauisng this error? Where can I get that info? Whenever we see the above message in ULS logs, we are also experiencing blocking in SQL Server and users are facing very slow performance. Please advice Thanks

SSIS FOR each loop to load 1 file after other into database for particaular folder

HI I am using ssis 2008,i have folder in which i have 10 excel file.i wont to load them one after other in data  base I have created a Dataflow task that load one file into database.i have inserted this dataflow task into For each loop and in For each loop i have give that folder path and *.XLSX  and in variable mapping i have created one variable  which i have passed in Database destination connecion string (properties->expression) but still i get error "cannot acquire connection from connection manager" please guide me or provide me with some reference so that i cud load file from folder into database one after other

Deleting the file from sharepoint folder gives error

Hi All, I am trying to delete a file from sharepoint it show error like this: <Result ID=\"1,Delete\" xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\"><ErrorCode>0x80070005</ErrorCode><ErrorText>The operation failed because an unexpected error occurred. (Result Code: 0x80070005)</ErrorText>

Insert Into SQL Server, With Current File Uploader Count

I have a Multiple File Uploader named "Attachments1" , and to get the cound I used "Attachments1.items.count"... then I have a Insert Into Command for SQL Server, that Inserts information into the table for every item in "Attachments1", you can see the below code... For Each item As AttachmentItem In Attachments1.Items             Dim objConn2 As New SqlConnection("Data Source=XXX")             objConn2.Open()             Dim objCmd2 As New SqlCommand("INSERT INTO clientport (name, event, phone, email, date1, password, path, path2, filename, number)" & "VALUES (@name, @event, @phone, @email, @date1, @password, @path, @path2, @filename, @number)", objConn2) But for the "number" Column, I would like to insert the Count for that file... For example if Attachments1 has 3 files it will insert into the database the time (which works fine)  the probem is the number column doesnt make file1 for the first file, file 2 for the second file, and file3 for the third file... Instead it puts file3 for all three rows when it Inserts into the DB.  my code is below to get the count.   Dim strcommandtext As String = ""    

Dealing with a changing folder value in Foreach File Enumerator

I have a Foreach Loop component that loops through files in a folder.  That folder doesn't exist on the server where I'm going to move the package to.  Within the Foreach Loop Editor, the Enumerator Configuration Folder doesn't appear to be able to take a variable value.  Also, it doesn't appear that there's a "Folder" property in the expressions property list. Is there some way I can use a variable value for this foreach file loop's folder location?  I need to move the package to the dev server and then eventually to the prod server.  I don't mind manually opening the *.dtsx file on each server to change the values accordingly, but I would think there's a better way. Any advice you could offer would be greatly appreciated.  The dev and prod servers have SQL Server 2008 R2 with SSIS 2008 R2 on Windows 2008 Server. Thanks, everybody.

DataView upload save file goes nowhere. How do you set a folder to upload to? Dynamically?

I have a Dataview bound to Document Library with the New Document button enabled. It apears to upload but can't find the files anywhere. I don't have a Shared Document folder. How and where do you set where to upload the file? A specific folder would be nice and If I could make it dynamic tied to QueryString Ideal. Going a bit further, the library I'm bound to has many 3 digit numeric folders that are dynamically created when entries are added to another list. The page that is calling my dataview has a querystring that will tie into the folder I want to drop files into. Just wondering how I can dynamically set the upload destination. Currently this is the generated code: <input type="button" value="Save" name="btnSave" onclick="javascript: {ddwrt:GenFireServerEvent('__commit')}" /> <a href="javascript: {ddwrt:GenFireServerEvent('__cancel;dvt_1_form_insertmode={1}')}">Upload File</a> I have some other code that calls the classic file upload page that is working perfectly, but I'd really prefer the clean and simple UI of the DataView control if I could make it work. Thanks!

Scheduled Folder and File cleanup


Does moss have a built in way to schedule file and folder deletion besides "disposition approval"? (i.e. every 90 days) If not built in, what options are out there? Thanks.

Master Page with CCS file in a Folder


I have a CCS file that I used with my MasterPage, however I wanted to move it with my other Style Sheets to a folder called StyleSheets.  But when I update the:

<link href="~/StyleSheets/SS_TDBG.css" rel="stylesheet" type="text/css" />

I lose my background image?

Here is my StyleSheet:




how to set a client folder to get upload and download the file.


i create a web site for uploading and download but i require that a folder create in client side if client download the file these file automatically save 

SP to fetch the specific file name in a specified folder



How to fetch a file name of specific  file type from a specified folder. To simplify

Assume 'Test.xxx'  is the file name in 'D:\test' folder. Need a sp which takes the drive as input parameter and fetch the output 'Test'.

Thanks in advance.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend