本文介绍了在sharepoint 2007列表中导入文本文件数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨所有



i想问我是否可以读取文本文件数据并将其导入到sharepoint列表项目

其实我想要阅读员工考勤卡读卡器文本文件,并将其数据导入到包含员工数据的列表中:员工姓名,NO,时间,超时,以便使用sharepoint 2007创建考勤跟踪软件



i感谢您的任何建议,请将您的意见发送给我以实现我的目标



谢谢

hi all

i want to ask if i could read text file data and import it to sharepoint list items
in fact i want to read employees time attendance card reader text file and import its data to a list contain employees data sch as :employee name , NO,time in ,time out in order to create a time attendance tracking software using sharepoint 2007

i appreciate any suggestion ,please to send me your opinions to achieve my goal

Thanks

推荐答案

using (SPSite oSPsite = new SPSite("http://website url/"))
{
using (SPWeb oSPWeb = oSPsite.OpenWeb())
      {
            oSPWeb.AllowUnsafeUpdates = true;

            // Fetch the List
            SPList list = oSPWeb.Lists["MyList"];

            string[] lines = System.IO.File.ReadAllLines(@"C:\Users\Public\TestFolder\timesheetfile.txt");

            SPListItem itemToAdd = null;

            //Display the file contents by using a foreach loop.           
            foreach (string line in lines)
            {
            string[] arr = line.Split(",");

             //Add a new item in the List
            itemToAdd = list.Items.Add();
            itemToAdd["EmpName"] = Convert.Tostring(arr[0]);
            itemToAdd["EmpNumber"] = Convert.Tostring(arr[1]);
            itemToAdd["TimeIn"] = Convert.Tostring(arr[2]);
            itemToAdd["TimeOut"] = Convert.Tostring(arr[3]);
            itemToAdd.Update();

            }

             list.Update();
            oSPWeb.AllowUnsafeUpdates = false;
       }
}





如需时间安排:



我可以建议多种方式。喜欢你想要的东西。



方式1]创建一个计时器作业:这将读取.txt文件并使用服务器对象模型来执行CRUD操作。如果您不需要即时输入,请使用此解决方案。你可以按小时计划它,所以它会按小时读取条目。



按照链接写入和理解计时器:

[]



方式2]创建自己的Windows实用程序{.exe}并在Windows操作系统调度程序中安排它。 .exe可以是控制台应用程序,其中包含用于执行CRUD操作的服务器端代码。在这里,您需要添加SharePoint DLL。

我个人不喜欢它,因为把.exe放在生产上并不是个好主意。



方式3]您可以使用SharePoint提供的默认服务,如List.asmx

在这种情况下,您可以创建空SharePoint项目,添加应用程序页面中添加了list.asmx的引用。然后从.txt文件中读取数据并上传到列表中。



参考此博客:

[]



参考我的回答同时:

[]



方式4]创建自己的WCF服务以执行CRUD操作并读取txt文件。

在IIS或共享p中托管它oint执行操作。

您可以将它与定时器作业或自定义实用程序集成{.exe}



哦这是一个巨大的解决方案。

希望你好好去:))



For scheduling :

I can suggest many way's. Prefer what you want.

Way 1] Create a Timer job : This will read .txt file and use server object model to perform CRUD operation. Use this solution in case you do not need instant entry. You can schedule it for hourly so it will read entry on hourly basis.

follow link to write and understand timer :
http://lamahashim.blogspot.in/2010/02/creating-timer-job-in-moss.html[^]

Way 2] Create you own Windows utility {.exe} and schedule it in windows OS scheduler. .exe can be console application which contains server side code to perform CRUD operations. Here you need to add SharePoint dll.
Personally i do not prefer it because put .exe on production is not good idea.

Way 3] You can use default service provided by SharePoint like List.asmx
In this case you can create empty SharePoint project, add application page the add reference of list.asmx in it. Then read data from .txt file and upload into list.

Refer this blog :
http://blogs.msdn.com/b/pranab/archive/2008/11/24/sharepoint-2007-moss-wss-using-lists-asmx-getlistitems.aspx[^]

Refer my answer as well :
C# code to upload document to Sharepoint without using Microsoft.Sharepoint DLL[^]

Way 4] Create your own WCF service to perform CRUD operations and read txt file.
Host it in IIS or in share point to perform operations.
You can integrate it with Timer job or with custom utility {.exe}

Oh that was huge solution.
Hope you are good to go :)


这篇关于在sharepoint 2007列表中导入文本文件数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 11:00
查看更多