在sharepoint 2007列表中导入文本文件数据 [英] import text file data in sharepoint 2007 list

查看:82
本文介绍了在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

推荐答案

朋友,



确保您的txt数据将来统一,以便于编写逻辑。



我很高兴它可以帮助你,我建议你阅读一个文件的逻辑。



之前开始我对txt文件的假设是:

1]在文件中写入的数据使得每个条目都在换行符上。 {或某些分隔符}

2]文件是可访问的,您有权阅读它。



现在按照以下链接进行实现你的代码。

链接

http://msdn.microsoft.com/en-us/library/vstudio/ezwyzy7b(v=vs.100).aspx

http://msdn.microsoft.com/en-us/library/db5x7c0d(v=vs.90).aspx



这是基本代码文件访问。

您可以读取数组中的所有数据,如下所示:



Friend,

Make sure your txt data is uniform in future so its easy to write logic.

I am happy it helps you and I am suggesting you a logic for reading a file.

Before begin my assumptions on txt file are :
1] data written in file is such that each entry is on newline. {or some separator }
2] file is accessible and you have permissions to read it.

Now follow below links and implement it in your code.
links
http://msdn.microsoft.com/en-us/library/vstudio/ezwyzy7b(v=vs.100).aspx
http://msdn.microsoft.com/en-us/library/db5x7c0d(v=vs.90).aspx

This is basic code for file access.
You can read all data in array or else, as below :

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操作。如果您不需要即时输入,请使用此解决方案。你可以按小时计划它,所以它会按小时读取条目。



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

http://lamahashim.blogspot.in/2010/02/creating-timer-job-in -moss.html [ ^ ]



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

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



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

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



参考此博客:

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



参考我的回答同时:

在不使用Microsoft.Sharepoint DLL的情况下将文档上传到Sharepoint的C#代码 [ ^ ]



方式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列表中导入文本文件数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆