Select Categories Below
Advertisement
Start Your Own Q&A Site
Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.
Status: Open Points: 75 Time: 13:10 - Aug 04, 2008
mythilimythili
I have a windows service that reads the files in directory on one server and loads them into another. So I' m using these lines of code to accomplish this. The problem is that I' m getting the format of the path specified is not the correct format. I' m not able to correct this all help would greatly be accomplished. thanks amulu protected void CopyImage() { // DAImage da = new DAImage(); string stylenum = ""; int itemid = 0; stylenum = "200899-01"; string filenum = ""; string newfilename = Guid.NewGuid().ToString () ; int index = 0; try { string[] files = System.IO.Directory.GetFiles(("\\\\Ccsrv2\\publicfiles\\All\\MARKETING\\Product Images\\Style Images\\August 2008 Market\\Test")); //(@"C:\\Documents and Settings\\mduddebanda\\My Documents\\My Pictures\\DeleteFolder"); foreach (string file in files) { index = file.IndexOf("."); filenum = file.Remove(index, 3); index = file.Length; filenum = file.Replace("\\", ""); index = filenum.Length; filenum = filenum.Substring(index - 13, 9); //filenum=file.Remove(index); //Response.Write(filenum); DataTable dtitem = DAImage.GetItembyStylenum(filenum); foreach (DataRow dr in dtitem.Rows) { stylenum = (dr[0].ToString()); itemid = Convert.ToInt16(dr[1].ToString()); } if (filenum == stylenum) // get the stylenum in the required format from the file here { //Get the image id for the image to be inserted into the table. DataTable dt = DAImage.GetImageId(); string result = ""; foreach (DataRow dr in dt.Rows) { result = dr[0].ToString(); } // System.IO.Directory.CreateDirectory(@"C:\\Documents and Settings\\mduddebanda\\My Documents\\My Pictures\\DeleteFolder\\tbl" + itemid); //System.IO.File.Copy(file, @"\\Pdserver.tsiag.com\d$\Library\tbl" + itemid + "\" + filenum + ".jpg"); System.IO.Directory.CreateDirectory(@"\\Pdserver\\d:$\\devlibrary\\tblItem" + itemid); // System.IO.File.Copy(file, @"C:\\Documents and Settings\\mduddebanda\\My Documents\\My Pictures\\DeleteFolder\\tbl" + itemid + "\\" + newfilename + ".jpg"); // System.IO.File.Copy(file, "\\\\Pdserver\\d$\\devlibrary\\tblItem" + itemid + "\\" + newfilename.ToString() + ".jpg"); System.IO.File.Copy(file, @"\\Pdserver.tsiag.com\\d:$\\Library\\tbl" + itemid + "\\" + filenum + ".jpg"); DAImage.InsertImage("\\tblItem" + itemid + "\\" + newfilename.ToString() + ".jpg", itemid); System.IO.File.Delete(file); } //select * from tblImage where imageid= (select max(imageid) from tblImage ) //Insert into the tblImage for that imageid and for that category. //then delete this file from The j:/ directory. } } catch (Exception ex) { throw ex; } }
Categories:
Add Categories
When adding more than one category, separate them with commas.
PeterNZ
Date:: Aug 04, 2008
Time:: 16:29
Hi, if you use "@" in front of a string every character inteh string is interpreted as a character and not as a control character. I.e. if you would do a "Console.WriteLine("Text1 \n\r Text2");" You would see "Text1 Text2" If you add a "@" in front of it so that it reads "Console.WriteLine(@"Text1 \n\r Text2");" You would see on your console window: "Text1 \n\r Text2" because "\n\r" is not interpreted as a control character but as part of the string. Here is a console app I wrote which should calrify things. I also show you another way to handle the filename and split it etc. by using a fileinfo object. Let me know if it helped you class Program { static void Main(string[] args) { Console.WriteLine("Version 1:"); //string[] files = System.IO.Directory.GetFiles(@"C:\temp"); string[] files = System.IO.Directory.GetFiles(@"\\192.168.1.4\temp"); foreach (string file in files) { Console.WriteLine(file); } Console.WriteLine("\n\rVersion 2:"); //string[] files = System.IO.Directory.GetFiles(@"C:\temp"); foreach (string file in files) { System.IO.FileInfo fileInfo = new System.IO.FileInfo(file); Console.WriteLine(fileInfo.Name.Replace(fileInfo.Extension,String.Empty)); } Console.WriteLine("Press Enter to exit..."); Console.Read(); } } Cheers Peter
Time:: 16:48
thanks very much for your response in detail. I now get an exception , I granted all permissions for my machine on the server for this particular folder(so that my machine has access to only this folder). I still have this problem. All suggestion would be greatly appreciated. Thanks Service cannot be started. System.UnauthorizedAccessException: Access to the path '\\Pdserver.tsiag.com\D$\devlibrary\images\tblItem338' is denied. at MyfirstService.Service1.CopyImage() in C:\Documents and Settings\mduddebanda\My Documents\Visual Studio 2005\Projects\MyfirstService\MyfirstService\Service1.cs:line 110 at MyfirstService.Service1.OnStart(String[] args) in C:\Documents and Settings\mduddebanda\My Documents\Visual Studio 2005\Projects\MyfirstService\MyfirstService\Service1.cs:line 21 at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)
Date:: Aug 05, 2008
Time:: 20:30
SOrry but I guess it is exactly what it says: "System.UnauthorizedAccessException: Access to the path '\\Pdserver.tsiag.com\D$\devlibrary\images\tblItem338' is denied. " You don't have access to the share. Can you try the IP address? Maybe the machine can't resolve your pdserver.tsiag.com? Under which user do you run your windows service? Does THIS user has access? If it is the local system user then the local system user needs access etc. Go to Administrative Tools, select your service and check under what user it runs! Cheers Peter
admin
Date:: Mar 24, 2009
Time:: 09:49
The question looks to be abandoned by the user who asked it. If no action is taken within 2 days, a Quomon Moderator will consider closing the question and distributing the points. The Quomon Team
Answer this Question
New User
Email:
Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address
Registered User
Username:
Password:
Forgot Your Password?
Enter your email address below and we will resend your login information to you.
Login Information Sent
Questions
Hi is there a way to retrieve the loop count in XSLT
how do repair this problem: every times i opened my laptop it will suddenly n...
How i get the hp pavilion dv6-3054tx laptop bottom base assembly as a sparepa...
I don't have AOL browser but privacy scan shows hundreds of files/cookies fro...
wireless keyboard has stopped working
need validation controller for textbox in java
You have 100 characters to use
Rank
Expert
Points
1.
10279
2.
6493
3.
5596
4.
4848
5.
3487
6.
2840
7.
2770
8.
2303
9.
1820
10.
917
Register today to share your knowledge with the community and be recognized and rewarded for your contributions.
Register Here
"Psst, Quomon is a great site. Pass it on." Tell a Friend | Link To Us | Save to Delicious | Digg it
Language Options
English:
Español:
Sponsors
Questions and Answers Software