Register  |  Login

Question Details    

   Question

Time: 13:10 - Aug 04, 2008     Asked by: mythilimythili      Status: Unanswered      Points: 75   

windows service and file format exception.

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\\Pr
oduct 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;
}
}

Ask a New Question

Become a Quomon Expert

Current Categories

 

Other Questions Needing Answers


   

Answer Discussion
Answer Discussion
Answer Summaries
Answer Summary
 
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

Expert:

PeterNZ

Date:

Aug 04, 2008

Time:

16:29

 

Votes: Good (0) | Bad (0)
Login to rate this answer

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)

Expert:

mythilimythili

Date:

Aug 04, 2008

Time:

16:48

 

Votes: Good (0) | Bad (0)
Login to rate this answer

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

Expert:

PeterNZ

Date:

Aug 05, 2008

Time:

20:30

 

Votes: Good (0) | Bad (0)
Login to rate this answer

 

Answer Summary Currently Unavailable.

Answer Summaries cannot be submitted until the Answer Discussion is complete.

If you have an Answer for this question, submit it in the Answer Discussion area.




Respond to 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:


Forgotten Password

 
   

"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it


All Questions


Language Options

English:

www.quomon.com

Español:

www.quomon.es

Sponsors

Questions and Answers Software
Real Estate Postcards
Marketing Fulfillment